Skip to content

Commit

Permalink
fix: deployment recreated on every cdk deployment
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.
  • Loading branch information
corymhall committed Jan 19, 2024
1 parent 20ad55e commit 035d237
Show file tree
Hide file tree
Showing 16 changed files with 122 additions and 84 deletions.
27 changes: 1 addition & 26 deletions packages/@aws-cdk/aws-appconfig-alpha/lib/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { IApplication } from './application';
import { DeploymentStrategy, IDeploymentStrategy, RolloutStrategy } from './deployment-strategy';
import { IEnvironment } from './environment';
import { ActionPoint, IEventDestination, ExtensionOptions, IExtension, IExtensible, ExtensibleBase } from './extension';
import { getHash } from './private/hash';

/**
* Options for the Configuration construct
Expand Down Expand Up @@ -203,8 +202,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 @@ -309,8 +306,7 @@ abstract class ConfigurationBase extends Construct implements IConfiguration, IE
* @param environment The environment to deploy the configuration to
*/
public deploy(environment: IEnvironment) {
const logicalId = `Deployment${this.getDeploymentHash(environment)}`;
new CfnDeployment(this, logicalId, {
new CfnDeployment(this, `Deployment${environment.name!}`, {
applicationId: this.application.applicationId,
configurationProfileId: this.configurationProfileId,
deploymentStrategyId: this.deploymentStrategy!.deploymentStrategyId,
Expand Down Expand Up @@ -482,16 +478,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 @@ -623,17 +609,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": {
"MyHostedConfigDeploymentawsappconfigconfigurationMyAppConfigHostedEnvD1EED3BE0F97C0D3": {
"Type": "AWS::AppConfig::Deployment",
"Properties": {
"ApplicationId": {
Expand Down Expand Up @@ -213,7 +213,7 @@
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
},
"MyHostedConfigFromJsonDeploymentCD82E3049E374": {
"MyHostedConfigFromJsonDeploymentawsappconfigconfigurationMyAppConfigHostedEnvFromJson140D2DDD244BF117": {
"Type": "AWS::AppConfig::Deployment",
"Properties": {
"ApplicationId": {
Expand All @@ -233,7 +233,7 @@
}
}
},
"MyHostedConfigFromJsonDeploymentEFECDBC4087F1": {
"MyHostedConfigFromJsonDeploymentawsappconfigconfigurationMyAppConfigEnvDeployLater91038922BE3B2B72": {
"Type": "AWS::AppConfig::Deployment",
"Properties": {
"ApplicationId": {
Expand Down Expand Up @@ -278,7 +278,7 @@
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
},
"MyHostedConfigFromYamlDeploymentFE9624CBE5FC6": {
"MyHostedConfigFromYamlDeploymentawsappconfigconfigurationMyAppConfigHostedEnvFromYamlBB2C802A4CD2FE75": {
"Type": "AWS::AppConfig::Deployment",
"Properties": {
"ApplicationId": {
Expand Down Expand Up @@ -472,7 +472,7 @@
]
}
},
"MyConfigFromParameterDeployment0C84B4B3BAD6B": {
"MyConfigFromParameterDeploymentawsappconfigconfigurationMyAppConfigParameterEnv803E803A981AE384": {
"Type": "AWS::AppConfig::Deployment",
"Properties": {
"ApplicationId": {
Expand Down Expand Up @@ -593,7 +593,7 @@
}
}
},
"MyConfigFromDocumentDeployment1520EE7C916D3": {
"MyConfigFromDocumentDeploymentawsappconfigconfigurationMyAppConfigDocumentEnv5B0DCEC50DD481E9": {
"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.

Loading

0 comments on commit 035d237

Please sign in to comment.