Skip to content

Commit f9552c0

Browse files
authored
chore(codepipeline): revert "cannot deploy pipeline stack with crossAccountKeys twice" (#20427)
This PR fails in CDK v2 because the added unit tests that use `testFutureBehavior` fail on the CDK v2 branch. I believe they're failing because the `testFutureBehavior` utility function was written before CDK v2 was released, and so it automatically discards all feature flags - which should not be happening for new feature flags. I'm not sure what the best fix for this is so I'm just reverting it for the time being to unblock the release. Test logs: <details> ``` FAIL test/pipeline.test.js (12.04 s) ● › cross account key alias name tests › cross account key alias is named with stack name instead of ID when feature flag is enabled Template has 1 resources with type AWS::KMS::Alias, but none match as expected. The closest result is: { "Type": "AWS::KMS::Alias", "Properties": { "AliasName": "alias/codepipeline-pipelinestackpipeline9db740af", "TargetKeyId": { "Fn::GetAtt": [ "PipelineArtifactsBucketEncryptionKey01D58D69", "Arn" ] } }, "UpdateReplacePolicy": "Delete", "DeletionPolicy": "Delete" } with the following mismatches: Expected alias/codepipeline-actual-stack-name-pipeline-0a412eb5 but received alias/codepipeline-pipelinestackpipeline9db740af at /Properties/AliasName (using objectLike matcher) 83 | const matchError = hasResourceProperties(this.template, type, props); 84 | if (matchError) { > 85 | throw new Error(matchError); | ^ 86 | } 87 | } 88 | at Template.hasResourceProperties (../assertions/lib/template.ts:85:13) at fn (test/pipeline.test.ts:500:33) at Object.<anonymous> (../../../tools/@aws-cdk/cdk-build-tools/lib/feature-flag.ts:34:35) ● › cross account key alias name tests › cross account key alias is named with generated stack name when stack name is undefined and feature flag is enabled Template has 1 resources with type AWS::KMS::Alias, but none match as expected. The closest result is: { "Type": "AWS::KMS::Alias", "Properties": { "AliasName": "alias/codepipeline-pipelinestackpipeline9db740af", "TargetKeyId": { "Fn::GetAtt": [ "PipelineArtifactsBucketEncryptionKey01D58D69", "Arn" ] } }, "UpdateReplacePolicy": "Delete", "DeletionPolicy": "Delete" } with the following mismatches: Expected alias/codepipeline-pipelinestack-pipeline-9db740af but received alias/codepipeline-pipelinestackpipeline9db740af at /Properties/AliasName (using objectLike matcher) 83 | const matchError = hasResourceProperties(this.template, type, props); 84 | if (matchError) { > 85 | throw new Error(matchError); | ^ 86 | } 87 | } 88 | at Template.hasResourceProperties (../assertions/lib/template.ts:85:13) at fn (test/pipeline.test.ts:525:33) at Object.<anonymous> (../../../tools/@aws-cdk/cdk-build-tools/lib/feature-flag.ts:34:35) ● › cross account key alias name tests › cross account key alias is named with stack name and nested stack ID when feature flag is enabled Template has 1 resources with type AWS::KMS::Alias, but none match as expected. The closest result is: { "Type": "AWS::KMS::Alias", "Properties": { "AliasName": "alias/codepipeline-toplevelstacknestedpipelinestackactualpipeline3161a537", "TargetKeyId": { "Fn::GetAtt": [ "ActualPipelineArtifactsBucketEncryptionKeyDF448A3D", "Arn" ] } }, "UpdateReplacePolicy": "Delete", "DeletionPolicy": "Delete" } with the following mismatches: Expected alias/codepipeline-actual-stack-name-nestedpipelinestack-actualpipeline-23a98110 but received alias/codepipeline-toplevelstacknestedpipelinestackactualpipeline3161a537 at /Properties/AliasName (using objectLike matcher) 83 | const matchError = hasResourceProperties(this.template, type, props); 84 | if (matchError) { > 85 | throw new Error(matchError); | ^ 86 | } 87 | } 88 | at Template.hasResourceProperties (../assertions/lib/template.ts:85:13) at fn (test/pipeline.test.ts:552:46) at Object.<anonymous> (../../../tools/@aws-cdk/cdk-build-tools/lib/feature-flag.ts:34:35) ● › cross account key alias name tests › cross account key alias is named with generated stack name and nested stack ID when stack name is undefined and feature flag is enabled Template has 1 resources with type AWS::KMS::Alias, but none match as expected. The closest result is: { "Type": "AWS::KMS::Alias", "Properties": { "AliasName": "alias/codepipeline-toplevelstacknestedpipelinestackactualpipeline3161a537", "TargetKeyId": { "Fn::GetAtt": [ "ActualPipelineArtifactsBucketEncryptionKeyDF448A3D", "Arn" ] } }, "UpdateReplacePolicy": "Delete", "DeletionPolicy": "Delete" } with the following mismatches: Expected alias/codepipeline-toplevelstack-nestedpipelinestack-actualpipeline-3161a537 but received alias/codepipeline-toplevelstacknestedpipelinestackactualpipeline3161a537 at /Properties/AliasName (using objectLike matcher) 83 | const matchError = hasResourceProperties(this.template, type, props); 84 | if (matchError) { > 85 | throw new Error(matchError); | ^ 86 | } 87 | } 88 | at Template.hasResourceProperties (../assertions/lib/template.ts:85:13) at fn (test/pipeline.test.ts:581:46) at Object.<anonymous> (../../../tools/@aws-cdk/cdk-build-tools/lib/feature-flag.ts:34:35) ● › cross account key alias name tests › cross account key alias is properly shortened to 256 characters when stack name is too long and feature flag is enabled Template has 1 resources with type AWS::KMS::Alias, but none match as expected. The closest result is: { "Type": "AWS::KMS::Alias", "Properties": { "AliasName": "alias/codepipeline-toolongactualpipelinewithextrasuperlongnamethatwillneedtobeshortenedduetothealsoverysuperextralongnameofthestackalsowithsomedifferentcharactersaddedtotheendc9bb503e", "TargetKeyId": { "Fn::GetAtt": [ "ActualPipelineWithExtraSuperLongNameThatWillNeedToBeShortenedDueToTheAlsoVerySuperExtraLongNameOfTheStackAlsoWithSomeDifferentCharactersAddedToTheEndArtifactsBucketEncryptionKeyABD1BD7F", "Arn" ] } }, "UpdateReplacePolicy": "Delete", "DeletionPolicy": "Delete" } with the following mismatches: Expected alias/codepipeline-actual-stack-needstobeshortenedduetothelengthofthisabsurdnamethatnooneshouldusebutitstillmighthappensowemusttestfohatwillneedtobeshortenedduetothealsoverysuperextralongnameofthestack-alsowithsomedifferentcharactersaddedtotheend-384b9343 but received alias/codepipeline-toolongactualpipelinewithextrasuperlongnamethatwillneedtobeshortenedduetothealsoverysuperextralongnameofthestackalsowithsomedifferentcharactersaddedtotheendc9bb503e at /Properties/AliasName (using objectLike matcher) 83 | const matchError = hasResourceProperties(this.template, type, props); 84 | if (matchError) { > 85 | throw new Error(matchError); | ^ 86 | } 87 | } 88 | at Template.hasResourceProperties (../assertions/lib/template.ts:85:13) at fn (test/pipeline.test.ts:609:33) at Object.<anonymous> (../../../tools/@aws-cdk/cdk-build-tools/lib/feature-flag.ts:34:35) ● › cross account key alias name tests › cross account key alias names do not conflict when the stack ID is the same and pipeline ID is the same and feature flag is enabled Template has 1 resources with type AWS::KMS::Alias, but none match as expected. The closest result is: { "Type": "AWS::KMS::Alias", "Properties": { "AliasName": "alias/codepipeline-stackidpipeline32fb88b3", "TargetKeyId": { "Fn::GetAtt": [ "PipelineArtifactsBucketEncryptionKey01D58D69", "Arn" ] } }, "UpdateReplacePolicy": "Delete", "DeletionPolicy": "Delete" } with the following mismatches: Expected alias/codepipeline-actual-stack-1-pipeline-b09fefee but received alias/codepipeline-stackidpipeline32fb88b3 at /Properties/AliasName (using objectLike matcher) 83 | const matchError = hasResourceProperties(this.template, type, props); 84 | if (matchError) { > 85 | throw new Error(matchError); | ^ 86 | } 87 | } 88 | at Template.hasResourceProperties (../assertions/lib/template.ts:85:13) at fn (test/pipeline.test.ts:643:34) at Object.<anonymous> (../../../tools/@aws-cdk/cdk-build-tools/lib/feature-flag.ts:34:35) ● › cross account key alias name tests › cross account key alias names do not conflict for nested stacks when pipeline ID is the same and nested stacks have the same ID when feature flag is enabled Template has 1 resources with type AWS::KMS::Alias, but none match as expected. The closest result is: { "Type": "AWS::KMS::Alias", "Properties": { "AliasName": "alias/codepipeline-stackidnestedpipelineid3e91360a", "TargetKeyId": { "Fn::GetAtt": [ "PIPELINEIDArtifactsBucketEncryptionKeyE292C50C", "Arn" ] } }, "UpdateReplacePolicy": "Delete", "DeletionPolicy": "Delete" } with the following mismatches: Expected alias/codepipeline-actual-stack-name-1-nested-pipeline-id-c8c9f252 but received alias/codepipeline-stackidnestedpipelineid3e91360a at /Properties/AliasName (using objectLike matcher) 83 | const matchError = hasResourceProperties(this.template, type, props); 84 | if (matchError) { > 85 | throw new Error(matchError); | ^ 86 | } 87 | } 88 | at Template.hasResourceProperties (../assertions/lib/template.ts:85:13) at fn (test/pipeline.test.ts:697:47) at Object.<anonymous> (../../../tools/@aws-cdk/cdk-build-tools/lib/feature-flag.ts:34:35) ● › cross account key alias name tests › cross account key alias names do not conflict for nested stacks when in the same stack but nested stacks have different IDs when feature flag is enabled Template has 1 resources with type AWS::KMS::Alias, but none match as expected. The closest result is: { "Type": "AWS::KMS::Alias", "Properties": { "AliasName": "alias/codepipeline-stackidfirstpipelineid5abca693", "TargetKeyId": { "Fn::GetAtt": [ "PIPELINEIDArtifactsBucketEncryptionKeyE292C50C", "Arn" ] } }, "UpdateReplacePolicy": "Delete", "DeletionPolicy": "Delete" } with the following mismatches: Expected alias/codepipeline-actual-stack-name-1-first-pipeline-id-3c59cb88 but received alias/codepipeline-stackidfirstpipelineid5abca693 at /Properties/AliasName (using objectLike matcher) 83 | const matchError = hasResourceProperties(this.template, type, props); 84 | if (matchError) { > 85 | throw new Error(matchError); | ^ 86 | } 87 | } 88 | at Template.hasResourceProperties (../assertions/lib/template.ts:85:13) at fn (test/pipeline.test.ts:749:46) at Object.<anonymous> (../../../tools/@aws-cdk/cdk-build-tools/lib/feature-flag.ts:34:35) ``` </details> ---- ### All Submissions: * [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent ae64183 commit f9552c0

File tree

21 files changed

+20
-672
lines changed

21 files changed

+20
-672
lines changed

Diff for: packages/@aws-cdk/aws-codepipeline-actions/test/cfn-template-from-repo.lit.integ.snapshot/aws-cdk-codepipeline-cloudformation.template.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"PipelineArtifactsBucketEncryptionKeyAlias5C510EEE": {
4545
"Type": "AWS::KMS::Alias",
4646
"Properties": {
47-
"AliasName": "alias/codepipeline-aws-cdk-codepipeline-cloudformation-pipeline-7dbde619",
47+
"AliasName": "alias/codepipeline-awscdkcodepipelinecloudformationpipeline7dbde619",
4848
"TargetKeyId": {
4949
"Fn::GetAtt": [
5050
"PipelineArtifactsBucketEncryptionKey01D58D69",

Diff for: packages/@aws-cdk/aws-codepipeline-actions/test/lambda-deployed-through-codepipeline.lit.integ.snapshot/PipelineStack.template.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"PipelineArtifactsBucketEncryptionKeyAlias5C510EEE": {
3939
"Type": "AWS::KMS::Alias",
4040
"Properties": {
41-
"AliasName": "alias/codepipeline-pipelinestack-pipeline-9db740af",
41+
"AliasName": "alias/codepipeline-pipelinestackpipeline9db740af",
4242
"TargetKeyId": {
4343
"Fn::GetAtt": [
4444
"PipelineArtifactsBucketEncryptionKey01D58D69",

Diff for: packages/@aws-cdk/aws-codepipeline-actions/test/lambda-pipeline.integ.snapshot/aws-cdk-codepipeline-lambda.template.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"PipelineArtifactsBucketEncryptionKeyAlias5C510EEE": {
3939
"Type": "AWS::KMS::Alias",
4040
"Properties": {
41-
"AliasName": "alias/codepipeline-aws-cdk-codepipeline-lambda-pipeline-87a4b3d3",
41+
"AliasName": "alias/codepipeline-awscdkcodepipelinelambdapipeline87a4b3d3",
4242
"TargetKeyId": {
4343
"Fn::GetAtt": [
4444
"PipelineArtifactsBucketEncryptionKey01D58D69",

Diff for: packages/@aws-cdk/aws-codepipeline-actions/test/pipeline-alexa-deploy.integ.snapshot/aws-cdk-codepipeline-alexa-deploy.template.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"PipelineArtifactsBucketEncryptionKeyAlias5C510EEE": {
4949
"Type": "AWS::KMS::Alias",
5050
"Properties": {
51-
"AliasName": "alias/codepipeline-aws-cdk-codepipeline-alexa-deploy-pipeline-961107f5",
51+
"AliasName": "alias/codepipeline-awscdkcodepipelinealexadeploypipeline961107f5",
5252
"TargetKeyId": {
5353
"Fn::GetAtt": [
5454
"PipelineArtifactsBucketEncryptionKey01D58D69",

Diff for: packages/@aws-cdk/aws-codepipeline-actions/test/pipeline-cfn.integ.snapshot/aws-cdk-codepipeline-cloudformation.template.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"PipelineArtifactsBucketEncryptionKeyAlias5C510EEE": {
3939
"Type": "AWS::KMS::Alias",
4040
"Properties": {
41-
"AliasName": "alias/codepipeline-aws-cdk-codepipeline-cloudformation-pipeline-7dbde619",
41+
"AliasName": "alias/codepipeline-awscdkcodepipelinecloudformationpipeline7dbde619",
4242
"TargetKeyId": {
4343
"Fn::GetAtt": [
4444
"PipelineArtifactsBucketEncryptionKey01D58D69",

Diff for: packages/@aws-cdk/aws-codepipeline-actions/test/pipeline-code-commit-build.integ.snapshot/aws-cdk-codepipeline-codecommit-codebuild.template.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@
244244
"PipelineArtifactsBucketEncryptionKeyAlias5C510EEE": {
245245
"Type": "AWS::KMS::Alias",
246246
"Properties": {
247-
"AliasName": "alias/codepipeline-aws-cdk-codepipeline-codecommit-codebuild-pipeline-9540e1f5",
247+
"AliasName": "alias/codepipeline-awscdkcodepipelinecodecommitcodebuildpipeline9540e1f5",
248248
"TargetKeyId": {
249249
"Fn::GetAtt": [
250250
"PipelineArtifactsBucketEncryptionKey01D58D69",

Diff for: packages/@aws-cdk/aws-codepipeline-actions/test/pipeline-code-commit.integ.snapshot/aws-cdk-codepipeline-codecommit.template.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
"PipelineArtifactsBucketEncryptionKeyAlias5C510EEE": {
110110
"Type": "AWS::KMS::Alias",
111111
"Properties": {
112-
"AliasName": "alias/codepipeline-aws-cdk-codepipeline-codecommit-pipeline-f780ca18",
112+
"AliasName": "alias/codepipeline-awscdkcodepipelinecodecommitpipelinef780ca18",
113113
"TargetKeyId": {
114114
"Fn::GetAtt": [
115115
"PipelineArtifactsBucketEncryptionKey01D58D69",

Diff for: packages/@aws-cdk/aws-codepipeline-actions/test/pipeline-events.integ.snapshot/aws-cdk-pipeline-event-target.template.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"MyPipelineArtifactsBucketEncryptionKeyAlias9D4F8C59": {
3939
"Type": "AWS::KMS::Alias",
4040
"Properties": {
41-
"AliasName": "alias/codepipeline-aws-cdk-pipeline-event-target-mypipeline-4ae5d407",
41+
"AliasName": "alias/codepipeline-awscdkpipelineeventtargetmypipeline4ae5d407",
4242
"TargetKeyId": {
4343
"Fn::GetAtt": [
4444
"MyPipelineArtifactsBucketEncryptionKey8BF0A7F3",

Diff for: packages/@aws-cdk/aws-codepipeline-actions/test/pipeline-stepfunctions.integ.snapshot/aws-cdk-codepipeline-stepfunctions.template.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"MyPipelineArtifactsBucketEncryptionKeyAlias9D4F8C59": {
7979
"Type": "AWS::KMS::Alias",
8080
"Properties": {
81-
"AliasName": "alias/codepipeline-aws-cdk-codepipeline-stepfunctions-mypipeline-ce88aa28",
81+
"AliasName": "alias/codepipeline-awscdkcodepipelinestepfunctionsmypipelinece88aa28",
8282
"TargetKeyId": {
8383
"Fn::GetAtt": [
8484
"MyPipelineArtifactsBucketEncryptionKey8BF0A7F3",

Diff for: packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts

+4-15
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
ArnFormat,
88
BootstraplessSynthesizer,
99
DefaultStackSynthesizer,
10-
FeatureFlags,
1110
IStackSynthesizer,
1211
Lazy,
1312
Names,
@@ -18,7 +17,6 @@ import {
1817
Stage as CdkStage,
1918
Token,
2019
} from '@aws-cdk/core';
21-
import * as cxapi from '@aws-cdk/cx-api';
2220
import { Construct } from 'constructs';
2321
import { ActionCategory, IAction, IPipeline, IStage, PipelineNotificationEvents, PipelineNotifyOnOptions } from './action';
2422
import { CfnPipeline } from './codepipeline.generated';
@@ -699,19 +697,10 @@ export class Pipeline extends PipelineBase {
699697
private generateNameForDefaultBucketKeyAlias(): string {
700698
const prefix = 'alias/codepipeline-';
701699
const maxAliasLength = 256;
702-
const maxResourceNameLength = maxAliasLength - prefix.length;
703-
// Names.uniqueId() may have naming collisions when the IDs of resources are similar
704-
// and/or when they are too long and sliced. We do not want to update this and
705-
// automatically change the name of every KMS key already generated so we are putting
706-
// this under a feature flag.
707-
const uniqueId = FeatureFlags.of(this).isEnabled(cxapi.CODEPIPELINE_CROSS_ACCOUNT_KEY_ALIAS_STACK_SAFE_UNIQUE_ID) ?
708-
Names.uniqueResourceName(this, {
709-
separator: '-',
710-
maxLength: maxResourceNameLength,
711-
allowedSpecialCharacters: '/_-',
712-
}) :
713-
Names.uniqueId(this).slice(-maxResourceNameLength);
714-
return prefix + uniqueId.toLowerCase();
700+
const uniqueId = Names.uniqueId(this);
701+
// take the last 256 - (prefix length) characters of uniqueId
702+
const startIndex = Math.max(0, uniqueId.length - (maxAliasLength - prefix.length));
703+
return prefix + uniqueId.substring(startIndex).toLowerCase();
715704
}
716705

717706
/**

Diff for: packages/@aws-cdk/aws-codepipeline/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"@aws-cdk/cdk-build-tools": "0.0.0",
8989
"@aws-cdk/integ-runner": "0.0.0",
9090
"@aws-cdk/cfn2ts": "0.0.0",
91+
"@aws-cdk/cx-api": "0.0.0",
9192
"@aws-cdk/pkglint": "0.0.0",
9293
"@types/jest": "^27.5.0",
9394
"jest": "^27.5.1"
@@ -99,7 +100,6 @@
99100
"@aws-cdk/aws-kms": "0.0.0",
100101
"@aws-cdk/aws-s3": "0.0.0",
101102
"@aws-cdk/core": "0.0.0",
102-
"@aws-cdk/cx-api": "0.0.0",
103103
"constructs": "^3.3.69"
104104
},
105105
"homepage": "https://github.com/aws/aws-cdk",
@@ -110,7 +110,6 @@
110110
"@aws-cdk/aws-kms": "0.0.0",
111111
"@aws-cdk/aws-s3": "0.0.0",
112112
"@aws-cdk/core": "0.0.0",
113-
"@aws-cdk/cx-api": "0.0.0",
114113
"constructs": "^3.3.69"
115114
},
116115
"engines": {

0 commit comments

Comments
 (0)