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: Stack Construct: when set stack-level tags with pseudo parameters such as Class Aws.STACK_NAME should emit error #29424

Closed
jiem-ying opened this issue Mar 10, 2024 · 3 comments
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug. effort/small Small work item – less than a day of effort p1 wontfix We have determined that we will not resolve the issue.

Comments

@jiem-ying
Copy link

Describe the bug

In previous closed issue "core: improve experience around stack-level tagging"
#4134

Should have feature "We should emit an error if you try to apply a tag that uses tokens to the Stack itself."

However, when use Stack Class to work on tags, example Python code

        bucket = s3.Bucket(self, "testCDKBucketwithImportedValuejiemying",
                           removal_policy= RemovalPolicy.DESTROY,
                           auto_delete_objects= True
                           )
        
        Stack.of(self).tags.set_tag("StackNameViaAws",Aws.STACK_NAME)

CDK ls and synthdo not emit the error, only when cdk deploy the expected invalid token value error will be incurred during stack operation when trying to tag resources in the scope:

Deployment failed: Error: The stack named CdkCaseworkingPythonStack failed to deploy: UPDATE_ROLLBACK_COMPLETE: Resource handler returned message: "1 validation error detected: Value '${Token[AWS.StackName.13]}' at 'tags.2.member.value' failed to satisfy constraint: Member must satisfy regular expression pattern: [\p{L}\p{Z}\p{N}_.:/=+\-@]* (Service: Iam, Status Code: 400, Request ID: df4a5550-9d06-4cc0-bd1d-46331da9858e)" (RequestToken: ce3f7dc0-4937-80e1-4b98-c639edead1b0, HandlerErrorCode: GeneralServiceException)

Expected Behavior

When user pass pseudo parameters such as Aws.STACK_NAME, and Aws.REGION to Stack Construct tags. An error should be given due to #4106 (comment)

Current Behavior

CDK ls and synth does not give error.

The Stack construct will pass {Token[AWS.StackName.13]} as stack-level tag value when CDK create-changeset, subsequently causing error when the stack level tags propagate to resources inside of the stack.

Reproduction Steps

  1. Create a tag-able resource in a CDK stack and set tags value with pseudo parameter Class Aws
        bucket = s3.Bucket(self, "testCDKBucketwithImportedValuejiemying",
                           removal_policy= RemovalPolicy.DESTROY,
                           auto_delete_objects= True
                           )
        
        Stack.of(self).tags.set_tag("StackNameViaAws",Aws.STACK_NAME)
  1. cdk deploy

Possible Solution

We should emit an error if you try to apply a tag that uses tokens to the Stack itself

Additional Information/Context

No response

CDK CLI Version

2.132.0

Framework Version

No response

Node.js Version

v20.11.1

OS

MacOS

Language

Python

Language Version

No response

Other information

No response

@jiem-ying jiem-ying added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 10, 2024
@github-actions github-actions bot added the @aws-cdk/aws-s3 Related to Amazon S3 label Mar 10, 2024
@pahud
Copy link
Contributor

pahud commented Mar 11, 2024

This error is from CloudFormation not CDK. Yes I think we should check that in setTag.

@pahud pahud added p2 p1 @aws-cdk/core Related to core CDK functionality effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. p2 @aws-cdk/aws-s3 Related to Amazon S3 labels Mar 11, 2024
@comcalvi comcalvi self-assigned this Apr 29, 2024
@GavinZZ GavinZZ changed the title Stack Construct: when set stack-level tags with pseudo parameters such as Class Aws.STACK_NAME should emit error core: Stack Construct: when set stack-level tags with pseudo parameters such as Class Aws.STACK_NAME should emit error May 17, 2024
@comcalvi comcalvi removed their assignment May 20, 2024
@comcalvi
Copy link
Contributor

comcalvi commented Aug 8, 2024

This will break existing functionality; we should not do this. See: #30022 (comment)

@comcalvi comcalvi closed this as completed Aug 8, 2024
Copy link

github-actions bot commented Aug 8, 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 Aug 8, 2024
@comcalvi comcalvi added the wontfix We have determined that we will not resolve the issue. label Aug 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug. effort/small Small work item – less than a day of effort p1 wontfix We have determined that we will not resolve the issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants