Skip to content

Commit 69c8944

Browse files
authored
feat(s3tables): implement ITaggableV2 on TableBucket and Table L2 constructs (#37277)
### Issue # (if applicable) Related to #33054. ### Reason for this change The L1 constructs (`CfnTableBucket`, `CfnTable`) implement `ITaggableV2`, so `Tags.of()` already propagates tags to the underlying CloudFormation resources. However, the L2 constructs (`TableBucket`, `Table`) don't formally implement `ITaggableV2`, which means: - `TagManager.of(tableBucket)` returns `undefined` on the L2 construct - The L2 constructs aren't discoverable as taggable by code that checks for `ITaggableV2` ### Description of changes Implement `ITaggableV2` on both `TableBucket` and `Table` L2 constructs by delegating `cdkTagManager` to the underlying L1 resource's tag manager (same pattern as `VpcOrigin` in `aws-cloudfront`). - `TableBucket` implements `ITaggableV2` with `cdkTagManager` delegated to `CfnTableBucket` - `Table` implements `ITaggableV2` with `cdkTagManager` delegated to `CfnTable` - Unit tests for construct-level and stack-level tag propagation (4 new tests) - README updated with tagging usage examples - Rosetta fixture updated with `Tags` import ### Describe any new or updated permissions being added N/A ### Description of how you validated changes 1. Built `@aws-cdk/aws-s3tables-alpha` — 0 errors, 0 warnings 2. Unit tests — 193 passed (4 new), coverage: 94.46% statements, 90.21% branches 3. Lint — ESLint + awslint + pkglint clean 4. Rosetta — README code samples compile 5. Integration test snapshots — 6/6 UNCHANGED ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent fc59d21 commit 69c8944

21 files changed

+35398
-6
lines changed

packages/@aws-cdk/aws-s3tables-alpha/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,18 @@ const permissions = new iam.PolicyStatement({
277277
table.addToResourcePolicy(permissions);
278278
```
279279

280+
### Tagging
281+
282+
Both `TableBucket` and `Table` support tagging through CDK's standard tagging mechanism:
283+
284+
```ts
285+
Tags.of(tableBucket).add('Environment', 'Production');
286+
Tags.of(table).add('Team', 'DataEngineering');
287+
288+
// Stack-level tags propagate to all resources
289+
Tags.of(stack).add('Project', 'DataLake');
290+
```
291+
280292
## Coming Soon
281293

282294
L2 Construct support for:

packages/@aws-cdk/aws-s3tables-alpha/lib/table-bucket.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { EOL } from 'os';
22
import * as iam from 'aws-cdk-lib/aws-iam';
33
import * as kms from 'aws-cdk-lib/aws-kms';
44
import * as s3tables from 'aws-cdk-lib/aws-s3tables';
5-
import type { IResource, RemovalPolicy } from 'aws-cdk-lib/core';
5+
import type { IResource, ITaggableV2, RemovalPolicy, TagManager } from 'aws-cdk-lib/core';
66
import { Resource, UnscopedValidationError, Token } from 'aws-cdk-lib/core';
77
import { memoizedGetter } from 'aws-cdk-lib/core/lib/helpers-internal';
88
import { addConstructMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
@@ -432,7 +432,7 @@ export interface TableBucketAttributes {
432432
* });
433433
*/
434434
@propertyInjectable
435-
export class TableBucket extends TableBucketBase {
435+
export class TableBucket extends TableBucketBase implements ITaggableV2 {
436436
/** Uniquely identifies this class. */
437437
public static readonly PROPERTY_INJECTION_ID: string = '@aws-cdk.aws-s3tables-alpha.TableBucket';
438438

@@ -596,6 +596,11 @@ export class TableBucket extends TableBucketBase {
596596
*/
597597
private readonly resource: s3tables.CfnTableBucket;
598598

599+
/**
600+
* The tag manager for this resource.
601+
*/
602+
public readonly cdkTagManager: TagManager;
603+
599604
/**
600605
* The resource policy for this tableBucket.
601606
*/
@@ -629,6 +634,7 @@ export class TableBucket extends TableBucketBase {
629634
metricsConfiguration: props.requestMetricsStatus ? { status: props.requestMetricsStatus } : undefined,
630635
});
631636

637+
this.cdkTagManager = this.resource.cdkTagManager;
632638
this.resource.applyRemovalPolicy(props.removalPolicy);
633639
}
634640

packages/@aws-cdk/aws-s3tables-alpha/lib/table.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import * as iam from 'aws-cdk-lib/aws-iam';
33
import { CfnTable, CfnTablePolicy } from 'aws-cdk-lib/aws-s3tables';
44
import type {
55
IResource,
6+
ITaggableV2,
67
RemovalPolicy,
8+
TagManager,
79
} from 'aws-cdk-lib/core';
810
import {
911
Resource,
@@ -634,7 +636,7 @@ export interface TableAttributes {
634636
* An S3 Table with helpers.
635637
*/
636638
@propertyInjectable
637-
export class Table extends TableBase {
639+
export class Table extends TableBase implements ITaggableV2 {
638640
/** Uniquely identifies this class. */
639641
public static readonly PROPERTY_INJECTION_ID: string = '@aws-cdk.aws-s3tables-alpha.Table';
640642

@@ -738,6 +740,11 @@ export class Table extends TableBase {
738740
*/
739741
private readonly _resource: CfnTable;
740742

743+
/**
744+
* The tag manager for this resource.
745+
*/
746+
public readonly cdkTagManager: TagManager;
747+
741748
/**
742749
* The name of this table
743750
*/
@@ -784,6 +791,7 @@ export class Table extends TableBase {
784791
this.namespace = props.namespace;
785792
this.tableName = props.tableName;
786793
this.tableArn = this._resource.attrTableArn;
794+
this.cdkTagManager = this._resource.cdkTagManager;
787795
this._resource.applyRemovalPolicy(props.removalPolicy);
788796
this.node.addDependency(this.namespace);
789797
}

packages/@aws-cdk/aws-s3tables-alpha/rosetta/default.ts-fixture

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Construct } from 'constructs';
2-
import { Stack } from 'aws-cdk-lib';
2+
import { Stack, Tags } from 'aws-cdk-lib';
33
import { TableBucket, UnreferencedFileRemovalStatus, TableBucketEncryption, RequestMetricsStatus, Namespace, Table, Status, OpenTableFormat, IcebergTransform, SortDirection, NullOrder } from '@aws-cdk/aws-s3tables-alpha';
44
import * as iam from 'aws-cdk-lib/aws-iam';
55
import * as kms from 'aws-cdk-lib/aws-kms';

packages/@aws-cdk/aws-s3tables-alpha/test/integration/integ.tagging.js.snapshot/TaggedTableBucketStack.assets.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-s3tables-alpha/test/integration/integ.tagging.js.snapshot/TaggedTableBucketStack.metadata.json

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"Resources": {
3+
"TaggedBucket5A84A2D2": {
4+
"Type": "AWS::S3Tables::TableBucket",
5+
"Properties": {
6+
"TableBucketName": "tagged-table-bucket",
7+
"Tags": [
8+
{
9+
"Key": "Environment",
10+
"Value": "Test"
11+
},
12+
{
13+
"Key": "Project",
14+
"Value": "S3Tables"
15+
}
16+
],
17+
"UnreferencedFileRemoval": {}
18+
},
19+
"UpdateReplacePolicy": "Delete",
20+
"DeletionPolicy": "Delete"
21+
}
22+
},
23+
"Outputs": {
24+
"ExportsOutputFnGetAttTaggedBucket5A84A2D2TableBucketARN325752C1": {
25+
"Value": {
26+
"Fn::GetAtt": [
27+
"TaggedBucket5A84A2D2",
28+
"TableBucketARN"
29+
]
30+
},
31+
"Export": {
32+
"Name": "TaggedTableBucketStack:ExportsOutputFnGetAttTaggedBucket5A84A2D2TableBucketARN325752C1"
33+
}
34+
}
35+
},
36+
"Parameters": {
37+
"BootstrapVersion": {
38+
"Type": "AWS::SSM::Parameter::Value<String>",
39+
"Default": "/cdk-bootstrap/hnb659fds/version",
40+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
41+
}
42+
},
43+
"Rules": {
44+
"CheckBootstrapVersion": {
45+
"Assertions": [
46+
{
47+
"Assert": {
48+
"Fn::Not": [
49+
{
50+
"Fn::Contains": [
51+
[
52+
"1",
53+
"2",
54+
"3",
55+
"4",
56+
"5"
57+
],
58+
{
59+
"Ref": "BootstrapVersion"
60+
}
61+
]
62+
}
63+
]
64+
},
65+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
66+
}
67+
]
68+
}
69+
}
70+
}

packages/@aws-cdk/aws-s3tables-alpha/test/integration/integ.tagging.js.snapshot/TaggedTableStack.assets.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-s3tables-alpha/test/integration/integ.tagging.js.snapshot/TaggedTableStack.metadata.json

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)