aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.65k stars 3.91k forks source link

(dynamodb): CfnGlobalTable is not taggable #26891

Closed colifran closed 1 year ago

colifran commented 1 year ago

Describe the bug

The GlobalTable L1 does not work with Tags because it does not implement the ITaggable interface.

Expected Behavior

Using Tags.of(...).add(...) should add tags to the resource and these should show up in the synthesized template.

Current Behavior

Tags.of(...).add(...) does not add Tags to the CfnGlobalTable resource - Tags are not rendered in the synthesized template.

As an example, this code:

const stack = new Stack(undefined, 'Stack', { env: { region: 'us-west-2' } });

  const globalTable = new CfnGlobalTable(stack, 'GlobalTable', {
    keySchema: [
      { attributeName: 'pk', keyType: 'HASH' },
    ],
    attributeDefinitions: [
      { attributeName: 'pk', attributeType: 'S' },
    ],
    replicas: [
      { region: 'us-west-2' },
      { region: 'us-east-1' },
    ],
  });
  Tags.of(globalTable).add('env', 'prod');

will produce the following template:

{
        "Resources": {
            "GlobalTable": {
                "Type": "AWS::DynamoDB::GlobalTable",
                "Properties": {
                    "AttributeDefinitions": [
                        {
                            "AttributeName": "pk",
                            "AttributeType": "S"
                        }
                    ],
                    "KeySchema": [
                        {
                            "AttributeName": "pk",
                            "KeyType": "HASH"
                        }
                    ],
                    "Replicas": [
                        {
                            "Region": "us-west-2"
                        },
                        {
                            "Region": "us-east-1"
                        }
                    ]
                }
            }
        },
        "Parameters": {
            "BootstrapVersion": {
                "Type": "AWS::SSM::Parameter::Value<String>",
                "Default": "/cdk-bootstrap/hnb659fds/version",
                "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
            }
        },
        "Rules": {
            "CheckBootstrapVersion": {
                "Assertions": [
                    {
                        "Assert": {
                            "Fn::Not": [
                                {
                                    "Fn::Contains": [
                                        [
                                            "1",
                                            "2",
                                            "3",
                                            "4",
                                            "5"
                                        ],
                                        {
                                            "Ref": "BootstrapVersion"
                                        }
                                    ]
                                }
                            ]
                        },
                        "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
                    }
                ]
            }
        }

Reproduction Steps

This can be reproduced with this code snippet also referenced above:

const stack = new Stack(undefined, 'Stack', { env: { region: 'us-west-2' } });

  const globalTable = new CfnGlobalTable(stack, 'GlobalTable', {
    keySchema: [
      { attributeName: 'pk', keyType: 'HASH' },
    ],
    attributeDefinitions: [
      { attributeName: 'pk', attributeType: 'S' },
    ],
    replicas: [
      { region: 'us-west-2' },
      { region: 'us-east-1' },
    ],
  });
  Tags.of(globalTable).add('env', 'prod');

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.93.0

Framework Version

No response

Node.js Version

v18.16.0

OS

Mac

Language

Typescript

Language Version

No response

Other information

No response

jumic commented 1 year ago

CloudFormation allows tagging for DynamoDB tables (CfnTable), see documentation: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html#cfn-dynamodb-table-tags

The CloudFormation resources for GlobalTables don't support tags. There's no tags attribute in the documentation: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-globaltable.html

In my opinion, this is the reason why CfnGlobalTable doesn't implement the ITaggable interface.

scanlonp commented 1 year ago

PR #27649 closes this issue.

github-actions[bot] commented 1 year ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.