Created
November 24, 2020 02:23
-
-
Save luketn/d9e1bca5a9766921dbe417d36f13c6f4 to your computer and use it in GitHub Desktop.
Customising Name Tags in CDK
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {StackProps} from "@aws-cdk/core"; | |
export interface BaseStackProps extends StackProps { | |
product: string; | |
environment: "development" | "production"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Aspects, Construct, IAspect, IConstruct, Stack, TagManager} from "@aws-cdk/core"; | |
import {ITaggable} from "@aws-cdk/core/lib/tag-manager"; | |
import {BaseStackProps} from "./base-stack-props"; | |
import {createNameTag, shouldHaveNameTag} from "./name-tags"; | |
export class BaseStack extends Stack { | |
constructor(scope: Construct, id: string, props: BaseStackProps) { | |
super(scope, id, props); | |
Aspects.of(this).add(new class implements IAspect { | |
public visit(construct: IConstruct): void { | |
if (TagManager.isTaggable(construct) && shouldHaveNameTag(construct)) { | |
let nameTag = createNameTag(construct, props); | |
construct.tags.setTag("Name", nameTag, 200); | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment