CDK Tagging: Stacks dont resolve Tags and autoDeleteObjects in S3 causes Stack level tagging to fail validation
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
I see two issues when Tagging at a Stack level.
1. At the Stack level awsApplication is set to a TOKEN Literal: `${Token[TOKEN.15]}`
2. When create an S3 Resource and setting the `autoDeleteObjects` property to `true` I get a validation error. I suspect it is passing the Token Literal OR there is a permission issue.
On Issue 2 using this: `Tags.of(this).add('awsApplication', Fn.importValue('AppTag'));`
results in
```
16:39:40 | UPDATE_FAILED | AWS::IAM::Role | CustomCDKBucketDep...erviceRole89A01265
Resource handler returned message: "1 validation error detected: Value '${Token[TOKEN.16]}' at 'tags.1.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: 11111)" (RequestToken: 1, HandlerErr11111
orCode: GeneralServiceException)
```
Failing at the step: CustomS3AutoDeleteObjectsCustomResourceProviderRole
Using: `Tags.of(this).add('awsApplication', Lazy.string({ produce: () => Fn.importValue('AppTag'),}));`
Results in:
```
Received response status [FAILED] from custom resource. Message returned: AccessDenied: User: arn:aws:sts::11111:assumed-role/Frontend-CustomS3AutoDeleteObjectsCusto-6lC587HvLiWH/Frontend-CustomS3AutoDeleteObjectsCust-8PVDc03FABEI is not authorized to perform: s3:GetBucketTagging on resource: "arn:aws:s3:::frontend-undefined8
```
### Regression Issue
- [ ] Select this option if this issue appears to be a regression.
### Last Known Working CDK Version
_No response_
### Expected Behavior
In the case of Number 1: I expect the Stack to be tagged with the ARN passed in.
In the case of Number 2: I expect the Stack to not Fail with a validation error and my bucket get created with the correct tags.
### Current Behavior
See Description
### Reproduction Steps
```typescript
#!/usr/bin/env node
import {
App,
RemovalPolicy,
Stack,
StackProps,
Tags,
} from "aws-cdk-lib";
import { CfnApplication } from "aws-cdk-lib/aws-servicecatalogappregistry";
import { Construct } from "constructs";
import { BlockPublicAccess, Bucket, BucketEncryption, ObjectOwnership } from 'aws-cdk-lib/aws-s3';
const app = new App();
export class Producer extends Stack {
public readonly applicationTagValue: string;
constructor(
scope: Construct,
id: string,
props?: StackProps,
) {
super(scope, id, props);
// Create an AppRegistry application
const myApplication = new CfnApplication(this, "CfnApplication", {
name: "MyApp",
description: `Core logic for managing MyApp automatically`,
});
this.applicationTagValue = myApplication.attrApplicationTagValue;
}
}
interface ConsumerProps extends StackProps {
applicationTagValue: string;
}
export class Consumer extends Stack {
constructor(scope: Construct, id: string, autodeleteobj: boolean, props: ConsumerProps) {
super(scope, id, props);
Tags.of(this).add("awsApplication", props.applicationTagValue, {
excludeResourceTypes: ["AWS::CloudFormation::Stack"],
});
const siteBucket = new Bucket(this, 'sitebucket', {
blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
encryption: BucketEncryption.S3_MANAGED,
versioned: false,
removalPolicy: RemovalPolicy.DESTROY,
autoDeleteObjects: autodeleteobj,
});
}
}
const producer = new Producer(app, "Producer");
const consumer_TokenLiteral = new Consumer(app, "consumerTokenLiteral", false, {
applicationTagValue: producer.applicationTagValue,
});
const consumer_ValidationFail = new Consumer(app, "consumerValidationFail", true, {
applicationTagValue: producer.applicationTagValue,
});
```
### Possible Solution
_No response_
### Additional Information/Context
_No response_
### CDK CLI Version
2.158.0 (build 4b8714d)
### Framework Version
_No response_
### Node.js Version
Node.js v22.8.0
### OS
MacOS (latest)
### Language
TypeScript
### Language Version
TypeScript 5.5.3
### Other information
Slack Thread detailing troubleshooting: https://cdk-dev.slack.com/archives/C018XT6REKT/p1725979817118299
Contributor guide
Research direction
Start by running the TypeScript Producer and Consumer reproduction with CDK CLI 2.158.0, comparing the token-literal case with autoDeleteObjects enabled. Trace stack-level Tags and the CustomS3AutoDeleteObjectsCustomResourceProviderRole path; done means the stack resolves the application tag and the bucket is created without validation or tagging-permission failures.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100