Created
October 31, 2020 13:02
-
-
Save michaelfecher/3f9adc6c7b60fed34d3af28ea53f979f to your computer and use it in GitHub Desktop.
AWS CDK - Configurabe values: Simple, independent (from deployment environment), but intransparent/
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
// source: https://github.com/michaelfecher/cdk-field-guide/blob/main/remove-hard-coded-values-and-use-variables/environment-variables/vpc-stack.ts | |
export class VpcStack extends Stack { | |
constructor(scope: Construct, id: string, props?: StackProps) { | |
super(scope, id, props); | |
// reading the value from the env. | |
// Obviously, you have to set it before or pass it before you call any cdk command | |
const vpcCidr = process.env.VPC_CIDR; | |
new Vpc(this, 'VPC', { | |
maxAzs: 3, | |
// using the value | |
cidr: vpcCidr, | |
subnetConfiguration: [ | |
{ | |
name: 'App', | |
subnetType: SubnetType.PRIVATE, | |
cidrMask: 24 | |
}, | |
// ... | |
] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment