Created
July 25, 2019 15:12
-
-
Save jewelsjacobs/981c7e24cd539e5ff4b8767a1af94373 to your computer and use it in GitHub Desktop.
pipeline app
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
| #!/usr/bin/env node | |
| import 'source-map-support/register'; | |
| import cdk = require('@aws-cdk/core'); | |
| import { VPCStack } from '../lib/vpc-stack'; | |
| import { PipelineStack } from '../lib/pipeline-stack'; | |
| import { DataStack } from '../lib/data-stack'; | |
| import ec2 = require('@aws-cdk/aws-ec2'); | |
| const app = new cdk.App(); | |
| // example [ 'us-west-1a', 'us-west-1b', 'us-west-1c' ] | |
| const availabilityZones = (region: string, zones: string[]) => { | |
| return zones.map((zone) => { | |
| return `${region}-${zone}` | |
| }) | |
| }; | |
| const publicCidrs = ['10.1.192.0/24', '10.1.194.0/24', '10.1.196.0/24'] | |
| const privateCidrs = ['10.1.193.0/24', '10.1.195.0/24', '10.1.197.0/24'] | |
| const vpcCIDR = '10.1.192.0/18'; | |
| const pipelineProps = { | |
| gitHubUsername: app.node.tryGetContext("github_owner"), | |
| repoName: app.node.tryGetContext("github_repo_name"), | |
| ssmGitHubTokenKey: process.env.GITHUB_TOKEN as string | |
| }; | |
| /** | |
| * AZs and Subnets for RDS: | |
| * | |
| * Even for a deployment entirely contained within a single Availability Zone (AZ), | |
| * you must create an extra subnet in a different AZ and include it in your DB Subnet Group. | |
| * The rationale for this requirement is to support high-availability Multi-AZ deployments. | |
| * @see{@link https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_VPC.WorkingWithRDSInstanceinaVPC.html#USER_VPC.CreateDBSubnetGroup} | |
| */ | |
| /** | |
| * Development | |
| * | |
| * DB instance is accessable tyo a client outside of the VPC | |
| * | |
| * @see{@link https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_VPC.Scenarios.html#USER_VPC.Scenario6} | |
| */ | |
| new VPCStack(app, 'VPCDev', { | |
| maxAZs: 2, | |
| natGateways: 1, | |
| availabilityZones: availabilityZones('us-east', ['1a', '1b']), | |
| publicCidrs: publicCidrs.slice(0, 2), // ['10.1.192.0/24', '10.1.194.0/24'] | |
| privateCidrs: privateCidrs.slice(0, 2), // ['10.1.193.0/24', '10.1.195.0/24'] | |
| vpcCIDR // '10.1.192.0/18' | |
| }); | |
| new DataStack(app, 'DataDev', { | |
| allowFromAnyIpv4: true, | |
| masterUsername: 'someCrazyMasterUsername', | |
| subnetType: ec2.SubnetType.PUBLIC, | |
| deleteAutomatedBackups: true, | |
| deletionProtection: false | |
| }); | |
| new PipelineStack(app, 'PipelineDev', { | |
| ...pipelineProps, | |
| serviceStacks: [ | |
| 'VPCDev', | |
| 'DataDev' | |
| ] | |
| }); | |
| /** | |
| * Production | |
| */ | |
| new VPCStack(app, 'VPCProd', { | |
| maxAZs: 3, | |
| natGateways: 2, | |
| availabilityZones: availabilityZones('us-west', ['1a', '1b', '1c']), | |
| publicCidrs, // ['10.1.192.0/24', '10.1.194.0/24', '10.1.196.0/24'] | |
| privateCidrs, // ['10.1.193.0/24', '10.1.195.0/24', '10.1.197.0/24'] | |
| vpcCIDR // '10.1.192.0/18' | |
| }); | |
| new DataStack(app, 'DataProd', { | |
| allowFromAnyIpv4: false, | |
| // @TODO work with encrypted secrets manager or paramater store | |
| masterUsername: 'idontKnowYet', | |
| subnetType: ec2.SubnetType.PRIVATE | |
| }); | |
| new PipelineStack(app, 'PipelineProd', { | |
| ...pipelineProps, | |
| serviceStacks: [ | |
| 'VPCProd', | |
| 'DataProd' | |
| ] | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment