Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Tags with value of False got evaluated to "" #3429

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion samtranslator/model/tags/resource_tagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions tests/translator/input/simple_function_with_tags_false.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Resources:
MyLambdaFunction:
ConnorRobertson marked this conversation as resolved.
Show resolved Hide resolved
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
ConnorRobertson marked this conversation as resolved.
Show resolved Hide resolved
Metadata:
SamTransformTest: true
18 changes: 18 additions & 0 deletions tests/translator/input/simple_table_with_tags_false.yaml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Loading