Skip to content

Commit

Permalink
fix: dropped explicit inclusion of 'crossAccountKeys: true' & 'reuseC…
Browse files Browse the repository at this point in the history
…rossRegionSupportStacks: true' from MultiDeployCodePipelineProps
  • Loading branch information
OrdonioSa committed Sep 21, 2022
1 parent 2c991cf commit f44d0a6
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 5 deletions.
66 changes: 66 additions & 0 deletions examples/multiDeploy.integ.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { App, DefaultStackSynthesizer, Environment, Stack, StackProps } from 'aws-cdk-lib';
import { Pipeline } from "aws-cdk-lib/aws-codepipeline";
import { Effect, PolicyStatement } from "aws-cdk-lib/aws-iam";
import { Key } from "aws-cdk-lib/aws-kms";
import { Bucket } from "aws-cdk-lib/aws-s3";
import { Topic } from 'aws-cdk-lib/aws-sns';
import { AwsCustomResource, AwsSdkCall } from "aws-cdk-lib/custom-resources";
import { CodePipelineSource } from 'aws-cdk-lib/pipelines';
import { Construct } from 'constructs';
import { AdditionalTrigger } from '../src';
Expand Down Expand Up @@ -31,7 +36,30 @@ class AppStack extends Stack {
}
}

const deploymentRegions = ['eu-central-1']

// cross account support stack setup
const pipeline = new Pipeline(stack, 'ExamplePipeline', {
crossRegionReplicationBuckets: deploymentRegions.reduce((prev: any, current) => {
prev[current] = Bucket.fromBucketAttributes(stack, `Bucket-${current}`, {
bucketName: new SSMParameterReader(stack, `SSMBucketName-${current}`, {
parameterName: '/tts-cloud/cloud-cicd-common-support-stacks/bucket-name',
region: current,
}).getParameterValue(),
encryptionKey: Key.fromKeyArn(stack, `Key-${current}`, new SSMParameterReader(stack, `SSMKeyArn-${current}`, {
parameterName: '/tts-cloud/cloud-cicd-common-support-stacks/key-arn',
region: current,
}).getParameterValue())
});
return prev;
}, {}),
crossAccountKeys: true,
restartExecutionOnUpdate: true,
});


new MultiDeployCodePipeline(stack, 'MultiDeployCodePipeline', {
codePipeline: pipeline,

synth: SynthProfiles.projenCdkApp(
CodePipelineSource.gitHub('ttskp/cdk-pipelines', 'main')
Expand Down Expand Up @@ -63,3 +91,41 @@ new MultiDeployCodePipeline(stack, 'MultiDeployCodePipeline', {
});

app.synth()

//region Cross-region SSMParameterReader
export interface SSMParameterReaderProps {
parameterName: string;
region: string;
}

export class SSMParameterReader extends AwsCustomResource {
constructor(scope: Construct, name: string, props: SSMParameterReaderProps) {
const { parameterName, region } = props;

const ssmAwsSdkCall: AwsSdkCall = {
service: 'SSM',
action: 'getParameter',
parameters: {
Name: parameterName
},
region,
physicalResourceId: { id: Date.now().toString() } // Update physical id to always fetch the latest version
};

super(scope, name, {
onUpdate: ssmAwsSdkCall, policy: {
statements: [new PolicyStatement({
resources: ['*'],
actions: ['ssm:GetParameter'],
effect: Effect.ALLOW,
}
)]
}
});
}

public getParameterValue(): string {
return this.getResponseField('Parameter.Value').toString();
}
}
//endregion
6 changes: 1 addition & 5 deletions src/pipelines/multiDeploy/MultiDeployCodePipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ export class MultiDeployCodePipeline extends CodePipeline {

constructor(scope: Construct, id: string, props: MultiDeployCodePipelineProps) {

const mdcProps = {
crossAccountKeys: true,
reuseCrossRegionSupportStacks: true,
...props,
};
const mdcProps = { ...props };

super(scope, id, mdcProps);
this.mdcProps = mdcProps;
Expand Down

0 comments on commit f44d0a6

Please sign in to comment.