Skip to content

Commit

Permalink
fix(appconfig): deployment recreated on every cdk deployment (#28782)
Browse files Browse the repository at this point in the history
Every time I perform a CDK deployment, the logicalId hash of the deployment resource changes and causes the deployment resource to be deleted and recreated. I'm assuming it is because the configuration `content` is part of the hash creation and I am creating the content using `lazy` and at the time of the hash creation it is still a token.

Looking at the [CloudFormation
docs](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appconfig-deployment.html) for the deployment resource, a change to _any_ property causes a replacement so I don't think we need to control the recreation logic ourselves, we should just let CloudFormation do the resource replacement for us.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
corymhall authored and GavinZZ committed Feb 22, 2024
1 parent 18d097e commit 1ea8e7e
Show file tree
Hide file tree
Showing 16 changed files with 122 additions and 83 deletions.
26 changes: 1 addition & 25 deletions packages/@aws-cdk/aws-appconfig-alpha/lib/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ abstract class ConfigurationBase extends Construct implements IConfiguration, IE
});
}

protected abstract getDeploymentHash(environment: IEnvironment): string;

/**
* Adds an extension defined by the action point and event destination
* and also creates an extension association to the configuration profile.
Expand Down Expand Up @@ -312,8 +310,7 @@ abstract class ConfigurationBase extends Construct implements IConfiguration, IE
* please take a look into https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_appconfig.CfnDeployment.html.
*/
public deploy(environment: IEnvironment) {
const logicalId = `Deployment${this.getDeploymentHash(environment)}`;
new CfnDeployment(this, logicalId, {
new CfnDeployment(this, `Deployment${getHash(environment.name!)}`, {
applicationId: this.application.applicationId,
configurationProfileId: this.configurationProfileId,
deploymentStrategyId: this.deploymentStrategy!.deploymentStrategyId,
Expand Down Expand Up @@ -485,16 +482,6 @@ export class HostedConfiguration extends ConfigurationBase {
this.addExistingEnvironmentsToApplication();
this.deployConfigToEnvironments();
}

protected getDeploymentHash(environment: IEnvironment): string {
const combinedString = `
${this.application!.name!}
${this.name!}
${environment.name!}
${this.content}
`;
return getHash(combinedString);
}
}

/**
Expand Down Expand Up @@ -626,17 +613,6 @@ export class SourcedConfiguration extends ConfigurationBase {
this.deployConfigToEnvironments();
}

protected getDeploymentHash(environment: IEnvironment): string {
const combinedString = `
${this.application!.name!}
${this.name!}
${environment.name!}
${this.versionNumber}
${this.location.type}
`;
return getHash(combinedString);
}

private getPolicyForRole(): iam.PolicyDocument {
const policy = new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
Expand Down
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
},
"MyHostedConfigDeploymentE4742E8E64DF4": {
"MyHostedConfigDeployment8E5DB1FCC9183": {
"Type": "AWS::AppConfig::Deployment",
"Properties": {
"ApplicationId": {
Expand Down Expand Up @@ -213,7 +213,7 @@
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
},
"MyHostedConfigFromJsonDeploymentCD82E3049E374": {
"MyHostedConfigFromJsonDeployment3AC6ED5A2933B": {
"Type": "AWS::AppConfig::Deployment",
"Properties": {
"ApplicationId": {
Expand All @@ -233,7 +233,7 @@
}
}
},
"MyHostedConfigFromJsonDeploymentEFECDBC4087F1": {
"MyHostedConfigFromJsonDeploymentFA00BC528601D": {
"Type": "AWS::AppConfig::Deployment",
"Properties": {
"ApplicationId": {
Expand Down Expand Up @@ -278,7 +278,7 @@
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
},
"MyHostedConfigFromYamlDeploymentFE9624CBE5FC6": {
"MyHostedConfigFromYamlDeploymentD93A5BDCCAAB2": {
"Type": "AWS::AppConfig::Deployment",
"Properties": {
"ApplicationId": {
Expand Down Expand Up @@ -472,7 +472,7 @@
]
}
},
"MyConfigFromParameterDeployment0C84B4B3BAD6B": {
"MyConfigFromParameterDeployment28051DE6185BF": {
"Type": "AWS::AppConfig::Deployment",
"Properties": {
"ApplicationId": {
Expand Down Expand Up @@ -593,7 +593,7 @@
}
}
},
"MyConfigFromDocumentDeployment1520EE7C916D3": {
"MyConfigFromDocumentDeployment7A5BA9D7D69C3": {
"Type": "AWS::AppConfig::Deployment",
"Properties": {
"ApplicationId": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1ea8e7e

Please sign in to comment.