diff --git a/cdk/cdk.context.json b/cdk/cdk.context.json deleted file mode 100644 index 4a17fe3..0000000 --- a/cdk/cdk.context.json +++ /dev/null @@ -1,102 +0,0 @@ -{ - "vpc-provider:account=654654503876:filter.isDefault=true:region=us-east-1:returnAsymmetricSubnets=true": { - "vpcId": "vpc-035d95b8dce96bda0", - "vpcCidrBlock": "172.31.0.0/16", - "ownerAccountId": "654654503876", - "availabilityZones": [], - "subnetGroups": [ - { - "name": "Public", - "type": "Public", - "subnets": [ - { - "subnetId": "subnet-02b0636a3177d196d", - "cidr": "172.31.32.0/20", - "availabilityZone": "us-east-1a", - "routeTableId": "rtb-0638d225ec6e9458e" - }, - { - "subnetId": "subnet-0e9c4ddc02d5fa081", - "cidr": "172.31.0.0/20", - "availabilityZone": "us-east-1b", - "routeTableId": "rtb-0638d225ec6e9458e" - }, - { - "subnetId": "subnet-00f70da087f5f6f96", - "cidr": "172.31.80.0/20", - "availabilityZone": "us-east-1c", - "routeTableId": "rtb-0638d225ec6e9458e" - }, - { - "subnetId": "subnet-0b1fe4dfdf22c7d23", - "cidr": "172.31.16.0/20", - "availabilityZone": "us-east-1d", - "routeTableId": "rtb-0638d225ec6e9458e" - }, - { - "subnetId": "subnet-01417bb32e385ffbb", - "cidr": "172.31.48.0/20", - "availabilityZone": "us-east-1e", - "routeTableId": "rtb-0638d225ec6e9458e" - }, - { - "subnetId": "subnet-06091dddac94451f0", - "cidr": "172.31.64.0/20", - "availabilityZone": "us-east-1f", - "routeTableId": "rtb-0638d225ec6e9458e" - } - ] - } - ] - }, - "vpc-provider:account=381491920629:filter.isDefault=true:region=us-east-1:returnAsymmetricSubnets=true": { - "vpcId": "vpc-047d7e829b5eecd2b", - "vpcCidrBlock": "172.31.0.0/16", - "ownerAccountId": "381491920629", - "availabilityZones": [], - "subnetGroups": [ - { - "name": "Public", - "type": "Public", - "subnets": [ - { - "subnetId": "subnet-01ee4104cc13170ec", - "cidr": "172.31.80.0/20", - "availabilityZone": "us-east-1a", - "routeTableId": "rtb-05f3921238acd8770" - }, - { - "subnetId": "subnet-035da13446b6f1dab", - "cidr": "172.31.16.0/20", - "availabilityZone": "us-east-1b", - "routeTableId": "rtb-05f3921238acd8770" - }, - { - "subnetId": "subnet-055afb00d3dc6ddfb", - "cidr": "172.31.32.0/20", - "availabilityZone": "us-east-1c", - "routeTableId": "rtb-05f3921238acd8770" - }, - { - "subnetId": "subnet-0c60cc5d50057f0d5", - "cidr": "172.31.0.0/20", - "availabilityZone": "us-east-1d", - "routeTableId": "rtb-05f3921238acd8770" - }, - { - "subnetId": "subnet-0100c290d236dee5c", - "cidr": "172.31.48.0/20", - "availabilityZone": "us-east-1e", - "routeTableId": "rtb-05f3921238acd8770" - }, - { - "subnetId": "subnet-0a7ab0f0da25bf9c5", - "cidr": "172.31.64.0/20", - "availabilityZone": "us-east-1f", - "routeTableId": "rtb-05f3921238acd8770" - } - ] - } - ] - } -} diff --git a/cdk/lib/application-layer.ts b/cdk/lib/application-layer.ts index b0e8d00..479ccdc 100644 --- a/cdk/lib/application-layer.ts +++ b/cdk/lib/application-layer.ts @@ -17,7 +17,7 @@ export interface ApplicationLayerStackProps extends StackProps { */ readonly domain: string; - readonly parentHostedZoneId: string; + readonly parentHostedZone: string; /** * Table where the partition key refers to the top-level element of recipes. @@ -61,7 +61,7 @@ export default class ApplicationLayerStack extends Stack { new CrossAccountZoneDelegationRecord(this, 'Delegate', { delegatedZone: hostedZone, - parentHostedZoneName: props.parentHostedZoneId, + parentHostedZoneName: props.parentHostedZone, delegationRole: props.delegationRole, }); diff --git a/cdk/lib/application-stage.ts b/cdk/lib/application-stage.ts index e676fc0..d22769b 100644 --- a/cdk/lib/application-stage.ts +++ b/cdk/lib/application-stage.ts @@ -2,11 +2,13 @@ import { Construct } from 'constructs'; import { Stage, StageProps } from 'aws-cdk-lib'; import PersistenceLayerStack from './persistence-layer'; import ApplicationLayerStack from './application-layer'; -import { ProjectEnvironment, sharedEnvironment } from './pipeline'; -import { SharedStack } from './shared'; +import { ProjectEnvironment } from './pipeline'; +import { HostedZoneDelegate } from './iam/delegation-role'; export interface MealPlannerStageProps extends StageProps { readonly env: ProjectEnvironment; + readonly parentHostedZone: string; + readonly roleWrapper: HostedZoneDelegate; } /** @@ -22,16 +24,12 @@ export default class MealPlannerStage extends Stage { constructor(scope: Construct, id: string, props: MealPlannerStageProps) { super(scope, id, props); - const sharedLayer = new SharedStack(this, 'SharedLayer', { - environment: props.env, - env: sharedEnvironment, - }); const persistanceLayer = new PersistenceLayerStack(this, 'PersistenceLayer'); new ApplicationLayerStack(this, 'ApplicationLayer', { - delegationRole: sharedLayer.roleWrapper.delegationRole, + delegationRole: props.roleWrapper.delegationRole, recipeTable: persistanceLayer.recipeTable, - domain: sharedLayer.roleWrapper.normalizedDomain, - parentHostedZoneId: sharedLayer.hostedZoneId, + domain: props.roleWrapper.normalizedDomain, + parentHostedZone: props.parentHostedZone, }); } } diff --git a/cdk/lib/pipeline.ts b/cdk/lib/pipeline.ts index 3fac07d..77f5b08 100644 --- a/cdk/lib/pipeline.ts +++ b/cdk/lib/pipeline.ts @@ -74,11 +74,39 @@ export default class PipelineStack extends Stack { crossAccountKeys: true, }); + const projectsHostedZone = HostedZone.fromHostedZoneId( + this, + 'ProjectsHostedZone', + 'Z09758583PVMFV16WNRXR', + ); + + const stagingHostedZoneDelegate = new HostedZoneDelegate( + this, + `${stagingEnvironment.name}HostedZoneDelegate`, + { + hostedZoneArn: projectsHostedZone.hostedZoneArn, + projectEnvironment: stagingEnvironment, + }); + projectsHostedZone.grantDelegation(stagingHostedZoneDelegate.delegationRole); + + const prodHostedZoneDelegate = new HostedZoneDelegate( + this, + `${prodEnvironment.name}HostedZoneDelegate`, + { + hostedZoneArn: projectsHostedZone.hostedZoneArn, + projectEnvironment: prodEnvironment, + }); + projectsHostedZone.grantDelegation(prodHostedZoneDelegate.delegationRole); + const stagingStage = new MealPlannerStage(this, 'MealPlannerAppStaging', { env: stagingEnvironment, + roleWrapper: stagingHostedZoneDelegate, + parentHostedZone: 'projects.chittyinsights.com', }); const prodStage = new MealPlannerStage(this, 'MealPlannerAppProd', { env: prodEnvironment, + roleWrapper: prodHostedZoneDelegate, + parentHostedZone: 'projects.chittyinsights.com', }); pipeline.addStage(stagingStage); diff --git a/cdk/lib/shared.ts b/cdk/lib/shared.ts deleted file mode 100644 index bab817b..0000000 --- a/cdk/lib/shared.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { Stack, StackProps } from 'aws-cdk-lib'; -import { HostedZone } from 'aws-cdk-lib/aws-route53'; -import { Construct } from 'constructs'; -import { HostedZoneDelegate } from './iam/delegation-role'; -import { ProjectEnvironment } from './pipeline'; - -export interface SharedStackProps extends StackProps { - readonly environment: ProjectEnvironment; -} - -/** - * Stack for holding shared resources. - * - * For some reason, CDK isn't a huge fan a deploying resources within it's pipeline stack. - */ -export class SharedStack extends Stack { - public readonly hostedZoneId: string; - public readonly roleWrapper: HostedZoneDelegate; - /** - * Build the stack resources. - * @param{Construct} scope parent - * @param{string} id logical id - * @param{SharedStackProps} props properties - */ - constructor(scope: Construct, id: string, props: SharedStackProps) { - super(scope, id, props); - - const projectsHostedZone = HostedZone.fromHostedZoneId( - this, - 'ProjectsHostedZone', - 'Z09758583PVMFV16WNRXR', - ); - this.hostedZoneId = projectsHostedZone.hostedZoneId; - - this.roleWrapper = new HostedZoneDelegate( - this, - `${props.environment.name}HostedZoneDelegate`, - { - hostedZoneArn: projectsHostedZone.hostedZoneArn, - projectEnvironment: props.environment, - }); - projectsHostedZone.grantDelegation(this.roleWrapper.delegationRole); - } -}