8000 add support for fn::select in conditional (#9311) · codeperl/localstack@6d2cc7c · GitHub
[go: up one dir, main page]

Skip to content

Commit 6d2cc7c

Browse files
authored
add support for fn::select in conditional (localstack#9311)
1 parent 7fc2ccc commit 6d2cc7c

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

localstack/services/cloudformation/engine/template_utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,21 @@ def resolve_condition(
262262
]
263263
)
264264
return result
265+
case "Fn::Select":
266+
index = v[0]
267+
options = v[1]
268+
for i, option in enumerate(options):
269+
if isinstance(option, dict):
270+
options[i] = resolve_condition(
271+
account_id,
272+
region_name,
273+
option,
274+
conditions,
275+
parameters,
276+
mappings,
277+
stack_name,
278+
)
279+
return options[index]
265280
case "Fn::Sub":
266281
# we can assume anything in there is a ref
267282
if isinstance(v, str):

tests/aws/services/cloudformation/engine/test_conditions.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,15 @@ def test_conditional_in_conditional(self, env, region, deploy_cfn_template, aws_
396396
assert stack.outputs["Result"] == "true"
397397
else:
398398
assert stack.outputs["Result"] == "false"
399+
400+
@markers.aws.validated
401+
def test_conditional_with_select(self, deploy_cfn_template, aws_client):
402+
stack = deploy_cfn_template(
403+
template_path=os.path.join(
404+
os.path.dirname(__file__),
405+
"../../../templates/conditions/conditional-with-select.yml",
406+
),
407+
)
408+
409+
managed_policy_arn = stack.outputs["PolicyArn"]
410+
assert aws_client.iam.get_policy(PolicyArn=managed_policy_arn)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
3+
Conditions:
4+
IsGrapes: !Equals [!Select [ 1, ['apples', 'grapes', 'bananas']], 'grapes']
5+
6+
Resources:
7+
StreamWriterPolicy2:
8+
Type: 'AWS::IAM::ManagedPolicy'
9+
Condition: IsGrapes
10+
Properties:
11+
ManagedPolicyName: Test2
12+
PolicyDocument:
13+
Version: 2012-10-17
14+
Statement:
15+
- Effect: Allow
16+
Action: "kinesis:PutRecord"
17+
Resource: !Join
18+
- ':'
19+
- - arn:aws:kinesis
20+
- !Ref AWS::Region
21+
- !Ref AWS::AccountId
22+
- !Sub stream/${AWS::StackName}-*
23+
Outputs:
24+
PolicyArn:
25+
Description: StreamWriterPolicy2
26+
Value: !Ref StreamWriterPolicy2

0 commit comments

Comments
 (0)
0