-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix: local PropagateTags: false is not overridden by global PropagateTags: true #3978
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
Open
Adityaj0
wants to merge
2
commits into
aws:develop
Choose a base branch
from
Adityaj0:fix/implicit-api-propagate-tags-false-override
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
tests/translator/input/function_with_local_and_global_tags_merge.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| Globals: | ||
| Function: | ||
| Tags: | ||
| env: prod | ||
|
|
||
| Resources: | ||
| ApiFunction: # Adds a GET api endpoint at "/" to the ApiGatewayApi via an Api event | ||
| Type: AWS::Serverless::Function | ||
| Properties: | ||
| PropagateTags: true | ||
| Tags: | ||
| app: foo | ||
| Events: | ||
| ApiEvent: | ||
| Type: Api | ||
| Properties: | ||
| Path: / | ||
| Method: get | ||
| Runtime: python3.7 | ||
| Handler: index.handler | ||
| InlineCode: |- | ||
| def handler(event, context): | ||
| return {'body': 'Hello World!', 'statusCode': 200} |
22 changes: 22 additions & 0 deletions
22
tests/translator/input/function_with_local_propagate_tags_false_overrides_global_true.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| Globals: | ||
| Function: | ||
| PropagateTags: true | ||
| Tags: | ||
| test: 'yes' | ||
|
|
||
| Resources: | ||
| ApiFunction: # Adds a GET api endpoint at "/" to the ApiGatewayApi via an Api event | ||
| Type: AWS::Serverless::Function | ||
| Properties: | ||
| PropagateTags: false | ||
| Events: | ||
| ApiEvent: | ||
| Type: Api | ||
| Properties: | ||
| Path: / | ||
| Method: get | ||
| Runtime: python3.7 | ||
| Handler: index.handler | ||
| InlineCode: |- | ||
| def handler(event, context): | ||
| return {'body': 'Hello World!', 'statusCode': 200} |
163 changes: 163 additions & 0 deletions
163
tests/translator/output/aws-cn/function_with_local_and_global_tags_merge.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| { | ||
| "Resources": { | ||
| "ApiFunction": { | ||
| "Properties": { | ||
| "Code": { | ||
| "ZipFile": "def handler(event, context):\n return {'body': 'Hello World!', 'statusCode': 200}" | ||
| }, | ||
| "Handler": "index.handler", | ||
| "Role": { | ||
| "Fn::GetAtt": [ | ||
| "ApiFunctionRole", | ||
| "Arn" | ||
| ] | ||
| }, | ||
| "Runtime": "python3.7", | ||
| "Tags": [ | ||
| { | ||
| "Key": "env", | ||
| "Value": "prod" | ||
| }, | ||
| { | ||
| "Key": "app", | ||
| "Value": "foo" | ||
| } | ||
| ] | ||
| }, | ||
| "Type": "AWS::Lambda::Function" | ||
| }, | ||
| "ApiFunctionApiEventPermissionProd": { | ||
| "Properties": { | ||
| "Action": "lambda:InvokeFunction", | ||
| "FunctionName": { | ||
| "Ref": "ApiFunction" | ||
| }, | ||
| "Principal": "apigateway.amazonaws.com", | ||
| "SourceArn": { | ||
| "Fn::Sub": [ | ||
| "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", | ||
| { | ||
| "__ApiId__": { | ||
| "Ref": "ServerlessRestApi" | ||
| }, | ||
| "__Stage__": "*" | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| "Type": "AWS::Lambda::Permission" | ||
| }, | ||
| "ApiFunctionRole": { | ||
| "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" | ||
| ], | ||
| "Tags": [ | ||
| { | ||
| "Key": "env", | ||
| "Value": "prod" | ||
| }, | ||
| { | ||
| "Key": "app", | ||
| "Value": "foo" | ||
| } | ||
| ] | ||
| }, | ||
| "Type": "AWS::IAM::Role" | ||
| }, | ||
| "ServerlessRestApi": { | ||
| "Properties": { | ||
| "Body": { | ||
| "info": { | ||
| "title": { | ||
| "Ref": "AWS::StackName" | ||
| }, | ||
| "version": "1.0" | ||
| }, | ||
| "paths": { | ||
| "/": { | ||
| "get": { | ||
| "responses": {}, | ||
| "x-amazon-apigateway-integration": { | ||
| "httpMethod": "POST", | ||
| "type": "aws_proxy", | ||
| "uri": { | ||
| "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "swagger": "2.0" | ||
| }, | ||
| "EndpointConfiguration": { | ||
| "Types": [ | ||
| "REGIONAL" | ||
| ] | ||
| }, | ||
| "Parameters": { | ||
| "endpointConfigurationTypes": "REGIONAL" | ||
| }, | ||
| "Tags": [ | ||
| { | ||
| "Key": "env", | ||
| "Value": "prod" | ||
| }, | ||
| { | ||
| "Key": "app", | ||
| "Value": "foo" | ||
| } | ||
| ] | ||
| }, | ||
| "Type": "AWS::ApiGateway::RestApi" | ||
| }, | ||
| "ServerlessRestApiDeploymentb0ed1521b2": { | ||
| "Properties": { | ||
| "Description": "RestApi deployment id: b0ed1521b2c5e65da74d55d16b139143ae483503", | ||
| "RestApiId": { | ||
| "Ref": "ServerlessRestApi" | ||
| }, | ||
| "StageName": "Stage" | ||
| }, | ||
| "Type": "AWS::ApiGateway::Deployment" | ||
| }, | ||
| "ServerlessRestApiProdStage": { | ||
| "Properties": { | ||
| "DeploymentId": { | ||
| "Ref": "ServerlessRestApiDeploymentb0ed1521b2" | ||
| }, | ||
| "RestApiId": { | ||
| "Ref": "ServerlessRestApi" | ||
| }, | ||
| "StageName": "Prod", | ||
| "Tags": [ | ||
| { | ||
| "Key": "env", | ||
| "Value": "prod" | ||
| }, | ||
| { | ||
| "Key": "app", | ||
| "Value": "foo" | ||
| } | ||
| ] | ||
| }, | ||
| "Type": "AWS::ApiGateway::Stage" | ||
| } | ||
| } | ||
| } |
143 changes: 143 additions & 0 deletions
143
...nslator/output/aws-cn/function_with_local_propagate_tags_false_overrides_global_true.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| { | ||
| "Resources": { | ||
| "ApiFunction": { | ||
| "Properties": { | ||
| "Code": { | ||
| "ZipFile": "def handler(event, context):\n return {'body': 'Hello World!', 'statusCode': 200}" | ||
| }, | ||
| "Handler": "index.handler", | ||
| "Role": { | ||
| "Fn::GetAtt": [ | ||
| "ApiFunctionRole", | ||
| "Arn" | ||
| ] | ||
| }, | ||
| "Runtime": "python3.7", | ||
| "Tags": [ | ||
| { | ||
| "Key": "lambda:createdBy", | ||
| "Value": "SAM" | ||
| }, | ||
| { | ||
| "Key": "test", | ||
| "Value": "yes" | ||
| } | ||
| ] | ||
| }, | ||
| "Type": "AWS::Lambda::Function" | ||
| }, | ||
| "ApiFunctionApiEventPermissionProd": { | ||
| "Properties": { | ||
| "Action": "lambda:InvokeFunction", | ||
| "FunctionName": { | ||
| "Ref": "ApiFunction" | ||
| }, | ||
| "Principal": "apigateway.amazonaws.com", | ||
| "SourceArn": { | ||
| "Fn::Sub": [ | ||
| "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", | ||
| { | ||
| "__ApiId__": { | ||
| "Ref": "ServerlessRestApi" | ||
| }, | ||
| "__Stage__": "*" | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| "Type": "AWS::Lambda::Permission" | ||
| }, | ||
| "ApiFunctionRole": { | ||
| "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" | ||
| ], | ||
| "Tags": [ | ||
| { | ||
| "Key": "lambda:createdBy", | ||
| "Value": "SAM" | ||
| }, | ||
| { | ||
| "Key": "test", | ||
| "Value": "yes" | ||
| } | ||
| ] | ||
| }, | ||
| "Type": "AWS::IAM::Role" | ||
| }, | ||
| "ServerlessRestApi": { | ||
| "Properties": { | ||
| "Body": { | ||
| "info": { | ||
| "title": { | ||
| "Ref": "AWS::StackName" | ||
| }, | ||
| "version": "1.0" | ||
| }, | ||
| "paths": { | ||
| "/": { | ||
| "get": { | ||
| "responses": {}, | ||
| "x-amazon-apigateway-integration": { | ||
| "httpMethod": "POST", | ||
| "type": "aws_proxy", | ||
| "uri": { | ||
| "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "swagger": "2.0" | ||
| }, | ||
| "EndpointConfiguration": { | ||
| "Types": [ | ||
| "REGIONAL" | ||
| ] | ||
| }, | ||
| "Parameters": { | ||
| "endpointConfigurationTypes": "REGIONAL" | ||
| } | ||
| }, | ||
| "Type": "AWS::ApiGateway::RestApi" | ||
| }, | ||
| "ServerlessRestApiDeploymentb0ed1521b2": { | ||
| "Properties": { | ||
| "Description": "RestApi deployment id: b0ed1521b2c5e65da74d55d16b139143ae483503", | ||
| "RestApiId": { | ||
| "Ref": "ServerlessRestApi" | ||
| }, | ||
| "StageName": "Stage" | ||
| }, | ||
| "Type": "AWS::ApiGateway::Deployment" | ||
| }, | ||
| "ServerlessRestApiProdStage": { | ||
| "Properties": { | ||
| "DeploymentId": { | ||
| "Ref": "ServerlessRestApiDeploymentb0ed1521b2" | ||
| }, | ||
| "RestApiId": { | ||
| "Ref": "ServerlessRestApi" | ||
| }, | ||
| "StageName": "Prod" | ||
| }, | ||
| "Type": "AWS::ApiGateway::Stage" | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[BUG] The new merge unpacks both
Tagsvalues as mappings unconditionally, before theifguard:Two consequences that the previous
a or bform did not have:Tagsnow crashes the transform with a rawTypeError.Tagsis only type-checked much later, when the resource is constructed ("Tags": PropertyType(False, IS_DICT)insamtranslator/model/sam_resources.py:181);Parser.validate_datatypesonly verifies thatPropertiesis a map. So a CFN-style list, e.g.reaches this line and raises
TypeError: 'list' object is not a mapping.on_before_transform_templateonly catchesInvalidEventException, so it escapes as an unhandled error instead of the customer-facingInvalidResourceExceptionabout the invalidTagstype. Note this now happens even when tags are not propagated at all (PropagateTagsunset orfalse), because the merge is evaluated before theshould_propagate_tagscheck — previously that line was a plain assignment and the guard kept the bad value untouched.Tagsintrinsic gets corrupted. ForTags: {"Fn::If": [...]}the merge yields{"env": "prod", "Fn::If": [...]}, soFn::Ifbecomes a tag key on the implicit API. This also diverges from the Globals semantics the merge is meant to mirror:GlobalProperties._token_ofclassifies intrinsic dicts asPRIMITIVE, so_do_mergereturns_prefer_localand the function itself ends up with the local intrinsic only.Guarding the merge keeps both paths behaving as before: