-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat: support conditional AWS::NoValue in SAM Function's IAM Role #3842
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
Merged
+799
−8
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ef9cd22
Adding AWS::NoValue support to Serverless Function IAM role
6a37502
Merge branch 'develop' into develop
vicheey 79e8680
Added translator transform templated tests
b01c455
Merge branch 'develop' into develop
madsid cf96ad9
Adding condition for IAM resource
83e1f03
Adding condition for IAM role with if and else case
615f202
Addressing comments
026679c
Reformatted to make value changes in to_cloudformation
31cec02
Ignore PLR0912 too many branches
dc719c3
Merge branch 'develop' into develop
madsid 2403902
Simplify _make_lambda_role
c5676be
Adding iam_role_resource to _make_lambda_role
d55dda3
Merge branch 'develop' into develop
madsid 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
Some comments aren't visible on the classic Files Changed page.
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
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
8 changes: 8 additions & 0 deletions
8
tests/translator/input/error_function_invalid_iam_role_type.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,8 @@ | ||
| Resources: | ||
| MinimalFunction: | ||
| Type: AWS::Serverless::Function | ||
| Properties: | ||
| CodeUri: s3://sam-demo-bucket/hello.zip | ||
| Handler: hello.handler | ||
| Runtime: python3.10 | ||
| Role: 2 |
20 changes: 20 additions & 0 deletions
20
tests/translator/input/function_with_conditional_iam_role_else.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,20 @@ | ||
| Parameters: | ||
| iamRoleArn: | ||
| Type: String | ||
| Description: The ARN of an IAM role to use as this function's execution role. | ||
| If a role isn't specified, one is created for you with a logical ID of <function-logical-id>Role. | ||
|
|
||
| Conditions: | ||
| CreateRole: !Not [!Equals ['', !Ref iamRoleArn]] | ||
|
|
||
| Resources: | ||
| MinimalFunction: | ||
| Type: AWS::Serverless::Function | ||
| Properties: | ||
| CodeUri: s3://sam-demo-bucket/hello.zip | ||
| Handler: hello.handler | ||
| Runtime: python3.10 | ||
| Role: !If | ||
| - CreateRole | ||
| - !Ref "AWS::NoValue" | ||
| - !Ref "iamRoleArn" |
20 changes: 20 additions & 0 deletions
20
tests/translator/input/function_with_conditional_iam_role_if.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,20 @@ | ||
| Parameters: | ||
| iamRoleArn: | ||
| Type: String | ||
| Description: The ARN of an IAM role to use as this function's execution role. | ||
| If a role isn't specified, one is created for you with a logical ID of <function-logical-id>Role. | ||
|
|
||
| Conditions: | ||
| RoleExists: !Not [!Equals ['', !Ref iamRoleArn]] | ||
|
|
||
| Resources: | ||
| MinimalFunction: | ||
| Type: AWS::Serverless::Function | ||
| Properties: | ||
| CodeUri: s3://sam-demo-bucket/hello.zip | ||
| Handler: hello.handler | ||
| Runtime: python3.10 | ||
| Role: !If | ||
| - RoleExists | ||
| - !Ref "iamRoleArn" | ||
| - !Ref "AWS::NoValue" |
14 changes: 14 additions & 0 deletions
14
tests/translator/output/aws-cn/error_function_invalid_iam_role_type.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,14 @@ | ||
| { | ||
| "_autoGeneratedBreakdownErrorMessage": [ | ||
| "Invalid Serverless Application Specification document. ", | ||
| "Number of errors found: 1. ", | ||
| "Resource with id [MinimalFunction] is invalid. ", | ||
| "Property 'Role' should be a string." | ||
| ], | ||
| "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MinimalFunction] is invalid. Property 'Role' should be a string.", | ||
| "errors": [ | ||
| { | ||
| "errorMessage": "Resource with id [MinimalFunction] is invalid. Property 'Role' should be a string." | ||
| } | ||
| ] | ||
| } |
86 changes: 86 additions & 0 deletions
86
tests/translator/output/aws-cn/function_with_conditional_iam_role_else.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,86 @@ | ||
| { | ||
| "Conditions": { | ||
| "CreateRole": { | ||
| "Fn::Not": [ | ||
| { | ||
| "Fn::Equals": [ | ||
| "", | ||
| { | ||
| "Ref": "iamRoleArn" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| "Parameters": { | ||
| "iamRoleArn": { | ||
| "Description": "The ARN of an IAM role to use as this function's execution role. If a role isn't specified, one is created for you with a logical ID of <function-logical-id>Role.", | ||
| "Type": "String" | ||
| } | ||
| }, | ||
| "Resources": { | ||
| "MinimalFunction": { | ||
| "Properties": { | ||
| "Code": { | ||
| "S3Bucket": "sam-demo-bucket", | ||
| "S3Key": "hello.zip" | ||
| }, | ||
| "Handler": "hello.handler", | ||
| "Role": { | ||
| "Fn::If": [ | ||
| "CreateRole", | ||
| { | ||
| "Fn::GetAtt": [ | ||
| "MinimalFunctionRole", | ||
| "Arn" | ||
| ] | ||
| }, | ||
| { | ||
| "Ref": "iamRoleArn" | ||
| } | ||
| ] | ||
| }, | ||
| "Runtime": "python3.10", | ||
| "Tags": [ | ||
| { | ||
| "Key": "lambda:createdBy", | ||
| "Value": "SAM" | ||
| } | ||
| ] | ||
| }, | ||
| "Type": "AWS::Lambda::Function" | ||
| }, | ||
| "MinimalFunctionRole": { | ||
| "Condition": "CreateRole", | ||
| "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" | ||
| } | ||
| ] | ||
| }, | ||
| "Type": "AWS::IAM::Role" | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.