diff --git a/samtranslator/model/tags/resource_tagging.py b/samtranslator/model/tags/resource_tagging.py index 8a216d593..788bfc46d 100644 --- a/samtranslator/model/tags/resource_tagging.py +++ b/samtranslator/model/tags/resource_tagging.py @@ -30,7 +30,7 @@ def get_tag_list(resource_tag_dict: Optional[Dict[str, Any]]) -> List[Dict[str, return tag_list for tag_key, tag_value in resource_tag_dict.items(): - tag = {_KEY: tag_key, _VALUE: tag_value if tag_value else ""} + tag = {_KEY: tag_key, _VALUE: tag_value if (tag_value is not None) else ""} tag_list.append(tag) return tag_list diff --git a/tests/translator/input/simple_function_with_global_tags_false.yaml b/tests/translator/input/simple_function_with_global_tags_false.yaml new file mode 100644 index 000000000..8ca243a8a --- /dev/null +++ b/tests/translator/input/simple_function_with_global_tags_false.yaml @@ -0,0 +1,28 @@ +Globals: + Function: + Tags: + TagKey1: TagValue1 + TagKey2: '' + TagKey3: false + TagKey4: true + TagKey5: 0 + +Resources: + MyLambdaFunction: + Type: AWS::Serverless::Function + Properties: + Handler: index.handler + Runtime: nodejs18.x + InlineCode: | + exports.handler = async (event, context, callback) => { + return { + statusCode: 200, + body: 'Success' + } + } + MemorySize: 128 + Policies: + - AWSLambdaRole + - AmazonS3ReadOnlyAccess +Metadata: + SamTransformTest: true diff --git a/tests/translator/input/simple_function_with_tags_false.yaml b/tests/translator/input/simple_function_with_tags_false.yaml new file mode 100644 index 000000000..5adee9fa1 --- /dev/null +++ b/tests/translator/input/simple_function_with_tags_false.yaml @@ -0,0 +1,24 @@ +Resources: + MyLambdaFunction: + Type: AWS::Serverless::Function + Properties: + Handler: index.handler + Runtime: nodejs18.x + InlineCode: | + exports.handler = async (event, context, callback) => { + return { + statusCode: 200, + body: 'Success' + } + } + MemorySize: 128 + Policies: + - AWSLambdaRole + - AmazonS3ReadOnlyAccess + Tags: + TagKey1: TagValue1 + TagKey2: '' + TagKey3: false + TagKey4: true +Metadata: + SamTransformTest: true diff --git a/tests/translator/input/simple_table_with_tags_false.yaml b/tests/translator/input/simple_table_with_tags_false.yaml new file mode 100644 index 000000000..a0817238b --- /dev/null +++ b/tests/translator/input/simple_table_with_tags_false.yaml @@ -0,0 +1,18 @@ +Parameters: + TagValueParam: + Type: String + Default: value + +Resources: + MinimalTableWithTags: + Type: AWS::Serverless::SimpleTable + Properties: + Tags: + TagKey1: TagValue1 + TagKey2: '' + TagKey3: + Ref: TagValueParam + TagKey4: '123' + TagKey5: true + TagKey6: false + TagKey7: 0 diff --git a/tests/translator/output/aws-cn/simple_function_with_global_tags_false.json b/tests/translator/output/aws-cn/simple_function_with_global_tags_false.json new file mode 100644 index 000000000..355a796e3 --- /dev/null +++ b/tests/translator/output/aws-cn/simple_function_with_global_tags_false.json @@ -0,0 +1,102 @@ +{ + "Metadata": { + "SamTransformTest": true + }, + "Resources": { + "MyLambdaFunction": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event, context, callback) => {\n return {\n statusCode: 200,\n body: 'Success'\n }\n}\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "MyLambdaFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs18.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + }, + { + "Key": "TagKey1", + "Value": "TagValue1" + }, + { + "Key": "TagKey2", + "Value": "" + }, + { + "Key": "TagKey3", + "Value": false + }, + { + "Key": "TagKey4", + "Value": true + }, + { + "Key": "TagKey5", + "Value": 0 + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyLambdaFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaRole", + "arn:aws-cn:iam::aws:policy/AmazonS3ReadOnlyAccess" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + }, + { + "Key": "TagKey1", + "Value": "TagValue1" + }, + { + "Key": "TagKey2", + "Value": "" + }, + { + "Key": "TagKey3", + "Value": false + }, + { + "Key": "TagKey4", + "Value": true + }, + { + "Key": "TagKey5", + "Value": 0 + } + ] + }, + "Type": "AWS::IAM::Role" + } + } +} diff --git a/tests/translator/output/aws-cn/simple_function_with_tags_false.json b/tests/translator/output/aws-cn/simple_function_with_tags_false.json new file mode 100644 index 000000000..14c4e3962 --- /dev/null +++ b/tests/translator/output/aws-cn/simple_function_with_tags_false.json @@ -0,0 +1,94 @@ +{ + "Metadata": { + "SamTransformTest": true + }, + "Resources": { + "MyLambdaFunction": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event, context, callback) => {\n return {\n statusCode: 200,\n body: 'Success'\n }\n}\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "MyLambdaFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs18.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + }, + { + "Key": "TagKey1", + "Value": "TagValue1" + }, + { + "Key": "TagKey2", + "Value": "" + }, + { + "Key": "TagKey3", + "Value": false + }, + { + "Key": "TagKey4", + "Value": true + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyLambdaFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaRole", + "arn:aws-cn:iam::aws:policy/AmazonS3ReadOnlyAccess" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + }, + { + "Key": "TagKey1", + "Value": "TagValue1" + }, + { + "Key": "TagKey2", + "Value": "" + }, + { + "Key": "TagKey3", + "Value": false + }, + { + "Key": "TagKey4", + "Value": true + } + ] + }, + "Type": "AWS::IAM::Role" + } + } +} diff --git a/tests/translator/output/aws-cn/simple_table_with_tags_false.json b/tests/translator/output/aws-cn/simple_table_with_tags_false.json new file mode 100644 index 000000000..c86bf8b8a --- /dev/null +++ b/tests/translator/output/aws-cn/simple_table_with_tags_false.json @@ -0,0 +1,60 @@ +{ + "Parameters": { + "TagValueParam": { + "Default": "value", + "Type": "String" + } + }, + "Resources": { + "MinimalTableWithTags": { + "Properties": { + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "BillingMode": "PAY_PER_REQUEST", + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "Tags": [ + { + "Key": "TagKey1", + "Value": "TagValue1" + }, + { + "Key": "TagKey2", + "Value": "" + }, + { + "Key": "TagKey3", + "Value": { + "Ref": "TagValueParam" + } + }, + { + "Key": "TagKey4", + "Value": "123" + }, + { + "Key": "TagKey5", + "Value": true + }, + { + "Key": "TagKey6", + "Value": false + }, + { + "Key": "TagKey7", + "Value": 0 + } + ] + }, + "Type": "AWS::DynamoDB::Table" + } + } +} diff --git a/tests/translator/output/aws-us-gov/simple_function_with_global_tags_false.json b/tests/translator/output/aws-us-gov/simple_function_with_global_tags_false.json new file mode 100644 index 000000000..6be7de88a --- /dev/null +++ b/tests/translator/output/aws-us-gov/simple_function_with_global_tags_false.json @@ -0,0 +1,102 @@ +{ + "Metadata": { + "SamTransformTest": true + }, + "Resources": { + "MyLambdaFunction": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event, context, callback) => {\n return {\n statusCode: 200,\n body: 'Success'\n }\n}\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "MyLambdaFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs18.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + }, + { + "Key": "TagKey1", + "Value": "TagValue1" + }, + { + "Key": "TagKey2", + "Value": "" + }, + { + "Key": "TagKey3", + "Value": false + }, + { + "Key": "TagKey4", + "Value": true + }, + { + "Key": "TagKey5", + "Value": 0 + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyLambdaFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaRole", + "arn:aws-us-gov:iam::aws:policy/AmazonS3ReadOnlyAccess" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + }, + { + "Key": "TagKey1", + "Value": "TagValue1" + }, + { + "Key": "TagKey2", + "Value": "" + }, + { + "Key": "TagKey3", + "Value": false + }, + { + "Key": "TagKey4", + "Value": true + }, + { + "Key": "TagKey5", + "Value": 0 + } + ] + }, + "Type": "AWS::IAM::Role" + } + } +} diff --git a/tests/translator/output/aws-us-gov/simple_function_with_tags_false.json b/tests/translator/output/aws-us-gov/simple_function_with_tags_false.json new file mode 100644 index 000000000..71e53f69c --- /dev/null +++ b/tests/translator/output/aws-us-gov/simple_function_with_tags_false.json @@ -0,0 +1,94 @@ +{ + "Metadata": { + "SamTransformTest": true + }, + "Resources": { + "MyLambdaFunction": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event, context, callback) => {\n return {\n statusCode: 200,\n body: 'Success'\n }\n}\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "MyLambdaFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs18.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + }, + { + "Key": "TagKey1", + "Value": "TagValue1" + }, + { + "Key": "TagKey2", + "Value": "" + }, + { + "Key": "TagKey3", + "Value": false + }, + { + "Key": "TagKey4", + "Value": true + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyLambdaFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaRole", + "arn:aws-us-gov:iam::aws:policy/AmazonS3ReadOnlyAccess" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + }, + { + "Key": "TagKey1", + "Value": "TagValue1" + }, + { + "Key": "TagKey2", + "Value": "" + }, + { + "Key": "TagKey3", + "Value": false + }, + { + "Key": "TagKey4", + "Value": true + } + ] + }, + "Type": "AWS::IAM::Role" + } + } +} diff --git a/tests/translator/output/aws-us-gov/simple_table_with_tags_false.json b/tests/translator/output/aws-us-gov/simple_table_with_tags_false.json new file mode 100644 index 000000000..c86bf8b8a --- /dev/null +++ b/tests/translator/output/aws-us-gov/simple_table_with_tags_false.json @@ -0,0 +1,60 @@ +{ + "Parameters": { + "TagValueParam": { + "Default": "value", + "Type": "String" + } + }, + "Resources": { + "MinimalTableWithTags": { + "Properties": { + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "BillingMode": "PAY_PER_REQUEST", + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "Tags": [ + { + "Key": "TagKey1", + "Value": "TagValue1" + }, + { + "Key": "TagKey2", + "Value": "" + }, + { + "Key": "TagKey3", + "Value": { + "Ref": "TagValueParam" + } + }, + { + "Key": "TagKey4", + "Value": "123" + }, + { + "Key": "TagKey5", + "Value": true + }, + { + "Key": "TagKey6", + "Value": false + }, + { + "Key": "TagKey7", + "Value": 0 + } + ] + }, + "Type": "AWS::DynamoDB::Table" + } + } +} diff --git a/tests/translator/output/simple_function_with_global_tags_false.json b/tests/translator/output/simple_function_with_global_tags_false.json new file mode 100644 index 000000000..36b581200 --- /dev/null +++ b/tests/translator/output/simple_function_with_global_tags_false.json @@ -0,0 +1,102 @@ +{ + "Metadata": { + "SamTransformTest": true + }, + "Resources": { + "MyLambdaFunction": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event, context, callback) => {\n return {\n statusCode: 200,\n body: 'Success'\n }\n}\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "MyLambdaFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs18.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + }, + { + "Key": "TagKey1", + "Value": "TagValue1" + }, + { + "Key": "TagKey2", + "Value": "" + }, + { + "Key": "TagKey3", + "Value": false + }, + { + "Key": "TagKey4", + "Value": true + }, + { + "Key": "TagKey5", + "Value": 0 + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyLambdaFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/service-role/AWSLambdaRole", + "arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + }, + { + "Key": "TagKey1", + "Value": "TagValue1" + }, + { + "Key": "TagKey2", + "Value": "" + }, + { + "Key": "TagKey3", + "Value": false + }, + { + "Key": "TagKey4", + "Value": true + }, + { + "Key": "TagKey5", + "Value": 0 + } + ] + }, + "Type": "AWS::IAM::Role" + } + } +} diff --git a/tests/translator/output/simple_function_with_tags_false.json b/tests/translator/output/simple_function_with_tags_false.json new file mode 100644 index 000000000..0e205619c --- /dev/null +++ b/tests/translator/output/simple_function_with_tags_false.json @@ -0,0 +1,94 @@ +{ + "Metadata": { + "SamTransformTest": true + }, + "Resources": { + "MyLambdaFunction": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event, context, callback) => {\n return {\n statusCode: 200,\n body: 'Success'\n }\n}\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "MyLambdaFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs18.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + }, + { + "Key": "TagKey1", + "Value": "TagValue1" + }, + { + "Key": "TagKey2", + "Value": "" + }, + { + "Key": "TagKey3", + "Value": false + }, + { + "Key": "TagKey4", + "Value": true + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyLambdaFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/service-role/AWSLambdaRole", + "arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + }, + { + "Key": "TagKey1", + "Value": "TagValue1" + }, + { + "Key": "TagKey2", + "Value": "" + }, + { + "Key": "TagKey3", + "Value": false + }, + { + "Key": "TagKey4", + "Value": true + } + ] + }, + "Type": "AWS::IAM::Role" + } + } +} diff --git a/tests/translator/output/simple_table_with_tags_false.json b/tests/translator/output/simple_table_with_tags_false.json new file mode 100644 index 000000000..c86bf8b8a --- /dev/null +++ b/tests/translator/output/simple_table_with_tags_false.json @@ -0,0 +1,60 @@ +{ + "Parameters": { + "TagValueParam": { + "Default": "value", + "Type": "String" + } + }, + "Resources": { + "MinimalTableWithTags": { + "Properties": { + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "BillingMode": "PAY_PER_REQUEST", + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "Tags": [ + { + "Key": "TagKey1", + "Value": "TagValue1" + }, + { + "Key": "TagKey2", + "Value": "" + }, + { + "Key": "TagKey3", + "Value": { + "Ref": "TagValueParam" + } + }, + { + "Key": "TagKey4", + "Value": "123" + }, + { + "Key": "TagKey5", + "Value": true + }, + { + "Key": "TagKey6", + "Value": false + }, + { + "Key": "TagKey7", + "Value": 0 + } + ] + }, + "Type": "AWS::DynamoDB::Table" + } + } +}