Skip to content

Commit

Permalink
keep the tags behavior on TableV2
Browse files Browse the repository at this point in the history
  • Loading branch information
5d committed Oct 29, 2024
1 parent 17cbe63 commit 4e2481e
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 64 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,7 @@
"MaxReadRequestUnits": 222
},
"Region": "eu-west-1",
"TableClass": "STANDARD_INFREQUENT_ACCESS",
"Tags": [
{
"Key": "primaryTableTagKey",
"Value": "primaryTableTagValue"
}
]
"TableClass": "STANDARD_INFREQUENT_ACCESS"
},
{
"ContributorInsightsSpecification": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@
"Region": "us-east-2",
"TableClass": "STANDARD_INFREQUENT_ACCESS",
"Tags": [
{
"Key": "primaryTableTagKey",
"Value": "USE2Replica"
},
{
"Key": "USE2ReplicaTagKey",
"Value": "USE2ReplicaTagValue"
Expand Down Expand Up @@ -188,10 +184,6 @@
"Region": "us-west-2",
"TableClass": "STANDARD",
"Tags": [
{
"Key": "primaryTableTagKey",
"Value": "primaryTableTagValue"
},
{
"Key": "USW2ReplicaTagKey",
"Value": "USW2ReplicaTagValue"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,7 @@ class TestStack extends Stack {
contributorInsights: false,
},
},
tags: [{
key: 'USE2ReplicaTagKey',
value: 'USE2ReplicaTagValue',
}, {
key: 'primaryTableTagKey',
value: 'USE2Replica',
}],
tags: [{ key: 'USE2ReplicaTagKey', value: 'USE2ReplicaTagValue' }],
},
{
region: 'us-west-2',
Expand Down
4 changes: 2 additions & 2 deletions packages/aws-cdk-lib/aws-dynamodb/lib/table-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export interface TableOptionsV2 {
readonly kinesisStream?: IStream;

/**
* Tags to be applied to the table or replica table
* Tags to be applied to the primary table (default replica table).
*
* @default - no tags
*/
Expand Down Expand Up @@ -533,7 +533,7 @@ export class TableV2 extends TableBaseV2 {
this.partitionKey = props.partitionKey;
this.hasSortKey = props.sortKey !== undefined;
this.region = this.stack.region;
this.tags = new TagManager(TagType.STANDARD, CfnGlobalTable.CFN_RESOURCE_TYPE_NAME, props.tags);
this.tags = new TagManager(TagType.STANDARD, CfnGlobalTable.CFN_RESOURCE_TYPE_NAME);

this.encryption = props.encryption;
this.encryptionKey = this.encryption?.tableKey;
Expand Down
32 changes: 16 additions & 16 deletions packages/aws-cdk-lib/aws-dynamodb/test/table-v2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,10 +777,7 @@ describe('table', () => {
KMSMasterKeyId: 'arn:aws:kms:us-east-1:123456789012:key/g24efbna-az9b-42ro-m3bp-cq249l94fca6',
},
TableClass: 'STANDARD_INFREQUENT_ACCESS',
Tags: [
{ Key: 'USW2Key', Value: 'USW2Value' },
{ Key: 'USE1Key', Value: 'USE1Value' },
],
Tags: [{ Key: 'USE1Key', Value: 'USE1Value' }],
},
{
ContributorInsightsSpecification: {
Expand Down Expand Up @@ -816,10 +813,7 @@ describe('table', () => {
KMSMasterKeyId: 'arn:aws:kms:us-east-2:123456789012:key/g24efbna-az9b-42ro-m3bp-cq249l94fca6',
},
TableClass: 'STANDARD',
Tags: [
{ Key: 'USW2Key', Value: 'USW2Value' },
{ Key: 'USE2Key', Value: 'USE2Value' },
],
Tags: [{ Key: 'USE2Key', Value: 'USE2Value' }],
},
{
ContributorInsightsSpecification: {
Expand Down Expand Up @@ -1328,7 +1322,7 @@ describe('replica tables', () => {
});
});

test('replica tags override global table tags', () => {
test('replica tags override tag aspect tags', () => {
// GIVEN
const stack = new Stack(undefined, 'Stack', { env: { region: 'us-east-1' } });

Expand All @@ -1337,28 +1331,34 @@ describe('replica tables', () => {
partitionKey: { name: 'pk', type: AttributeType.STRING },
replicas: [{
region: 'us-west-1',
tags: [{ key: 'tableTagProperty', value: 'replicaTagPropertyValue' }],
tags: [{ key: 'tableTagProperty', value: 'replicaW1TagPropertyValue' }],
}, {
region: 'us-west-2',
}],
tags: [{ key: 'tableTagProperty', value: 'globalTagPropertyValue' }],
tags: [{ key: 'tableTagProperty', value: 'defaultReplicaTagPropertyValue' }],
});

Tags.of(table).add('tagAspect', 'tagAspectValue');
Tags.of(table).add('tableTagProperty', 'tagAspectValue');

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::DynamoDB::GlobalTable', {
Replicas: [
{
Region: 'us-west-1',
Tags: [
{ Key: 'tableTagProperty', Value: 'replicaTagPropertyValue' },
{ Key: 'tagAspect', Value: 'tagAspectValue' },
{ Key: 'tableTagProperty', Value: 'replicaW1TagPropertyValue' },
],
},
{
Region: 'us-west-2',
Tags: [
{ Key: 'tableTagProperty', Value: 'tagAspectValue' },
],
},
{
Region: 'us-east-1',
Tags: [
{ Key: 'tableTagProperty', Value: 'globalTagPropertyValue' },
{ Key: 'tagAspect', Value: 'tagAspectValue' },
{ Key: 'tableTagProperty', Value: 'defaultReplicaTagPropertyValue' },
],
},
],
Expand Down

0 comments on commit 4e2481e

Please sign in to comment.