Created
June 11, 2020 15:26
-
-
Save ranman/6e2b09161babd5d2d59d9d4ab7c28cfe to your computer and use it in GitHub Desktop.
This file contains 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
export class BaseStack extends cdk.Stack { | |
public readonly stageName?: string; | |
public readonly serviceName?: string; | |
constructor(scope: cdk.Construct, id: string, props: IBaseStack) { | |
const superProps = { | |
...(props.stageName && { stackName: `${props.stageName}-${id}` }), | |
...props, | |
}; | |
super(scope, id, superProps); | |
if (props.stageName) { | |
this.stageName = props.stageName; | |
cdk.Tag.add(this, "Stage", props.stageName); | |
} | |
if (props.serviceName) { | |
this.serviceName = this.serviceName; | |
cdk.Tag.add(this, "Service", props.serviceName); | |
} | |
} | |
public allocateLogicalId(element: cdk.CfnElement) { | |
const orig = super.allocateLogicalId(element); | |
return this.stageName ? this.stageName + orig : orig; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment