Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(core): When cloudformation spec adds a Tags property to an existing resource, this can break customer deployments or cause unexpected changes #15947

Open
madeline-k opened this issue Aug 9, 2021 · 2 comments
Labels
@aws-cdk/aws-cloudformation Related to AWS CloudFormation @aws-cdk/core Related to core CDK functionality bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@madeline-k
Copy link
Contributor

If a CDK user has added Tags to a construct, those tags will be added to all cloudformation resources within that construct's scope. If the Tags property was added to a resource via a cloudformation spec update, then when the CDK user updates their CDK version, a new Tags property will be added to that resource. This might not be what the user intended, and can cause deployment failures in some cases.

Reproduction Steps

Repro steps for one incarnation of this issue.

  1. Deploy below sample with CDK version 1.113.0 or below.
export class CodeDeploy extends cdk.Construct {
  constructor(scope: cdk.Stack, id: string, props: cdk.StackProps) {
    super(scope, id)
    
    const fn = new lambda.Function(this, 'MyLambda', {
      code: new lambda.InlineCode('foo'),
      handler: 'index.handler',
      runtime: lambda.Runtime.NODEJS_10_X,
    });
    const alias = new lambda.Alias(this, "alias", { aliasName: "Prod", version: fn.currentVersion })

    const deployment = new codedeploy.LambdaDeploymentGroup(this, "deployment-group", {
      alias,
    })

    // This adds a 'Name' tag to all cloudformation resources in the `deployment` construct's scope.
    cdk.Tags.of(deployment).add('Name', `buffer-${props.environment}`)
  }
}
  1. Upgrade to CDK version 1.114.0 or greater.

What did you expect to happen?

Deployment succeeds after upgrade.

What actually happened?

Deployment failed with error "Update to resource type AWS::CodeDeploy::Application is not supported" after upgrade, because the "Name" tag was added to the CodeDeploy::Application resource inside the LambdaDeploymentGroup construct.

Workaround

Explicitly remove tags from being added to specific resource types within your constructs.

const tagOptions = {
  excludeResourceTypes: ['AWS::CodeDeploy::Application'],
};
cdk.Tags.of(deployment).add('Name', `buffer-${props.environment}`, tagOptions);

This is 🐛 Bug Report

@madeline-k madeline-k added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 9, 2021
@github-actions github-actions bot added @aws-cdk/aws-cloudformation Related to AWS CloudFormation @aws-cdk/core Related to core CDK functionality labels Aug 9, 2021
@madeline-k madeline-k changed the title (core): cloudformation spec adds a Tags property to an existing resource, this can break customer deployments or cause unexpected changes (core): When cloudformation spec adds a Tags property to an existing resource, this can break customer deployments or cause unexpected changes Aug 9, 2021
@madeline-k madeline-k added p1 and removed needs-triage This issue or PR still needs to be triaged. labels Aug 9, 2021
@rix0rrr
Copy link
Contributor

rix0rrr commented Aug 11, 2021

The solution to this will probably involve some feature flag. I don't see how else it could work. I'm thinking:

{
  "context": {
    "@aws-cdk/core.taggableResources": "1.115.0"
  }
}

Which will only apply tags to resources that were considered taggable in 1.115.0, or something like that.

That might actually be hard, the CloudFormation spec version might be easier, but further removed from users:

{
  "context": {
    "@aws-cdk/core.taggableResources": "3.38.0"
  }
}

Uhh, what now?

Another alternative is to deprecate tree-based tagging and replace it with something more explicit.

@rix0rrr rix0rrr added the effort/medium Medium work item – several days of effort label Aug 11, 2021
@rix0rrr rix0rrr removed their assignment Aug 11, 2021
@polothy
Copy link
Contributor

polothy commented Aug 27, 2021

Just ran into this issue. Thank you very much for providing a workaround, worked like a charm!

Would tagging via the CloudFormation Stack avoid problems like this? For CodePipeline CloudFormation Actions, would have to generate a separate file for stack configuration (Scroll down to TemplateConfiguration here).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-cloudformation Related to AWS CloudFormation @aws-cdk/core Related to core CDK functionality bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

No branches or pull requests

4 participants