Skip to content

Commit

Permalink
add option to add custom AWS tags
Browse files Browse the repository at this point in the history
Signed-off-by: 馃惣 Samrose Ahmed 馃惣 <samroseahmed@gmail.com>
  • Loading branch information
Samrose-Ahmed committed Nov 5, 2022
1 parent e6f5eb4 commit 514b60a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions example/matano.config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
aws_account: "946413832404"
aws_region: "us-east-1"
aws_tags:
cost_center: "80432"

vpc:
id: vpc-05175918865d89771 # vpc-0ea06dd2385eeb53c
6 changes: 6 additions & 0 deletions infra/bin/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ const dpMainStack = new DPMainStack(app, "DPMainStack", {
realtimeBucketTopic: dpCommonStack.realtimeBucketTopic,
});

const userAwsTags = dpMainStack.userAwsTags ?? {};
if (userAwsTags.constructor !== Object || !Object.values(userAwsTags).every((x) => typeof x === "string")) {
throw new Error("Custom AWS tags must be key value object of strings.");
}

tagResources(app, () => ({
...userAwsTags,
"matano:managed": "true",
}));
6 changes: 6 additions & 0 deletions infra/lib/MatanoStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ export function tagResources(scope: Construct, tags: (stack: cdk.Stack) => Recor
export interface MatanoConfiguration {
aws_account: string | undefined;
aws_region: string | undefined;
aws_tags: object | undefined;
project_label: string | undefined;
is_production: boolean | undefined;
[key: string]: any;
}

export type MatanoConfig = MatanoConfiguration;
Expand Down Expand Up @@ -86,4 +88,8 @@ export class MatanoStack extends cdk.Stack {
get matanoContext() {
return JSON.parse(this.node.tryGetContext("matanoContext"));
}

get userAwsTags(): object | undefined {
return this.matanoConfig.aws_tags;
}
}
3 changes: 2 additions & 1 deletion infra/src/DPCommonStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class DPCommonStack extends MatanoStack {
this.matanoIngestionBucket = new S3BucketWithNotifications(this, "MatanoIngestionBucket", {
bucketProps: {
blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
}
},
});

this.matanoLakeStorageBucket = new S3BucketWithNotifications(this, "MatanoLakeStorageBucket", {
Expand Down Expand Up @@ -79,5 +79,6 @@ export class DPCommonStack extends MatanoStack {

// important: to prevent output deletion
this.exportValue(this.matanoIngestionBucket.topic.topicArn);
this.exportValue(this.matanoIngestionBucket.bucket.bucketArn);
}
}

0 comments on commit 514b60a

Please sign in to comment.