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

fix: deploy-time stack tags cause synthesis to fail #32041

Merged
merged 2 commits into from
Nov 6, 2024

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Nov 6, 2024

In #31457, we introduced a change that made synthesis fail if one of the stack tags was a deploy-time value. Since stack tags are assigned outside a CloudFormation context, deploy-time values cannot be evaluated, so the stack ends up with a tag like { Key: "my-tag", Value: "${Token[1234]}" }, which is probably not what is intended.

Worse, those tags are automatically propagated to all resources in the stack by CloudFormation, and some may validate the tag value and find that $ or any of the other characters are not valid tag values.

The intent was that customers would be alerted to these kinds of mistakes and apply their tags to resources, or skip stacks when applying tags to large scopes:

Tags.of(this).add('my-tag', Fn.importValue('SomeExport'), {
  excludeResourceTypes: ['aws:cdk:stack'],
});

The previous change was a bit drastic in its attempts. In this one we ignore the unresolved tags and add a warning instead. That way, synthesis still succeeds.

Closes #32040.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

In #31457, we introduced a change
that made synthesis fail if one of the stack tags was a deploy-time
value. Since stack tags are assigned outside a CloudFormation context,
deploy-time values cannot be evaluated, so the stack ends up with
a tag like `{ Key: "my-tag", Value: "${Token[1234]}" }`, which is
probably not what is intended.

Worse, those tags are automatically propagated to all resources in the
stack by CloudFormation, and some may validate the tag value and find
that `$` or any of the other characters are not valid tag values.

The intent was that customers would be alerted to these kinds of
mistakes and apply their tags to resources, or skip stacks
when applying tags to large scopes:

```ts
Tags.of(this).add('my-tag', Fn.importValue('SomeExport'), {
  excludeResourceTypes: ['aws:cdk:stack'],
});
```

The previous change was a bit drastic in its attempts.  In this one we
ignore the unresolved tags and add a warning instead. That way,
synthesis still succeeds.
@aws-cdk-automation aws-cdk-automation requested a review from a team November 6, 2024 19:45
@github-actions github-actions bot added the p2 label Nov 6, 2024
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Nov 6, 2024
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@rix0rrr rix0rrr added the pr-linter/exempt-integ-test The PR linter will not require integ test changes label Nov 6, 2024
@aws-cdk-automation aws-cdk-automation dismissed their stale review November 6, 2024 19:59

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Nov 6, 2024
Copy link
Contributor

mergify bot commented Nov 6, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mcintoac-aws
Copy link

mcintoac-aws commented Nov 6, 2024

To add slightly more context, a secondary behavior of tagging a Stack, as mentioned in the PR description, is to propagate the tag to all resources within the Stack. The previous change resulted in a breaking change where a user could be applying a deploy-time tag to a Stack for the purpose of propagating it to the rest of the Stack resources, without needing the tag to apply to the Stack itself.

This is not the ideal way to do this, since the stack type can be excluded as shown above, while still propagating the tag to all resources, and not triggering the thrown Error in the previous implementation.

The goal of this change should be (from my perspective) to still skip the tagging of the Stack, but rather than throw an error, display a warning, and importantly still propagate the tag to resources within the Stack to avoid breaking prior implementations. It should be on the user to decide whether to implement a different tagging strategy at the suggestion of the warning, while keeping the same functionality as before if the warning is not implemented.

All that being said, @rix0rrr can you confirm that this change keeps the propagating behavior of the tag to Stack resources even when the warning is triggered and the Stack tag is skipped? Assuming we don't want to introduce any breaking changes, the behavior should remain the same (don't tag Stack, still tag all resources) when a tag has a Token in it. i.e. the warning suggestion should be optional

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Nov 6, 2024
@kaizencc kaizencc added the pr/do-not-merge This PR should not be merged at this time. label Nov 6, 2024
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 91a75e3
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@rix0rrr rix0rrr removed the pr/do-not-merge This PR should not be merged at this time. label Nov 6, 2024
@rix0rrr
Copy link
Contributor Author

rix0rrr commented Nov 6, 2024

All that being said, @rix0rrr can you confirm that this change keeps the propagating behavior of the tag to Stack resources even when the warning is triggered and the Stack tag is skipped? Assuming we don't want to introduce any breaking changes, the behavior should remain the same (don't tag Stack, still tag all resources) when a tag has a Token in it. i.e. the warning suggestion should be optional

Hey @mcintoac-aws,

Yes I can confirm that. The reason because it works is because applying a Tag to a scope tags all the resources inside that scope.

So the reason that when you tag a stack, all resources inside the stack are tagged as well is not because the tag is applied to the stack, but because the tag is applied to the stack and all resources inside it.

The behavior in this PR only fails to apply the tag to the stack itself, but the propagating behavior of the tag is unchanged -- i.e., the tag is applied to the stack (dropped) and to all the resources (still applies).

Copy link
Contributor

mergify bot commented Nov 6, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 18c19fd into main Nov 6, 2024
21 checks passed
@mergify mergify bot deleted the huijbers/stack-tags-fail branch November 6, 2024 21:45
Copy link

github-actions bot commented Nov 6, 2024

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
contribution/core This is a PR that came from AWS. p2 pr-linter/exempt-integ-test The PR linter will not require integ test changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants