diff --git a/localstack/services/cloudformation/engine/template_utils.py b/localstack/services/cloudformation/engine/template_utils.py index 58f49dce8f8cf..3e4873b6a736d 100644 --- a/localstack/services/cloudformation/engine/template_utils.py +++ b/localstack/services/cloudformation/engine/template_utils.py @@ -262,6 +262,21 @@ def resolve_condition( ] ) return result + case "Fn::Select": + index = v[0] + options = v[1] + for i, option in enumerate(options): + if isinstance(option, dict): + options[i] = resolve_condition( + account_id, + region_name, + option, + conditions, + parameters, + mappings, + stack_name, + ) + return options[index] case "Fn::Sub": # we can assume anything in there is a ref if isinstance(v, str): diff --git a/tests/aws/services/cloudformation/engine/test_conditions.py b/tests/aws/services/cloudformation/engine/test_conditions.py index 33f30f21a7959..893c1c971d82a 100644 --- a/tests/aws/services/cloudformation/engine/test_conditions.py +++ b/tests/aws/services/cloudformation/engine/test_conditions.py @@ -396,3 +396,15 @@ def test_conditional_in_conditional(self, env, region, deploy_cfn_template, aws_ assert stack.outputs["Result"] == "true" else: assert stack.outputs["Result"] == "false" + + @markers.aws.validated + def test_conditional_with_select(self, deploy_cfn_template, aws_client): + stack = deploy_cfn_template( + template_path=os.path.join( + os.path.dirname(__file__), + "../../../templates/conditions/conditional-with-select.yml", + ), + ) + + managed_policy_arn = stack.outputs["PolicyArn"] + assert aws_client.iam.get_policy(PolicyArn=managed_policy_arn) diff --git a/tests/aws/templates/conditions/conditional-with-select.yml b/tests/aws/templates/conditions/conditional-with-select.yml new file mode 100644 index 0000000000000..f60e759118320 --- /dev/null +++ b/tests/aws/templates/conditions/conditional-with-select.yml @@ -0,0 +1,26 @@ +AWSTemplateFormatVersion: '2010-09-09' + +Conditions: + IsGrapes: !Equals [!Select [ 1, ['apples', 'grapes', 'bananas']], 'grapes'] + +Resources: + StreamWriterPolicy2: + Type: 'AWS::IAM::ManagedPolicy' + Condition: IsGrapes + Properties: + ManagedPolicyName: Test2 + PolicyDocument: + Version: 2012-10-17 + Statement: + - Effect: Allow + Action: "kinesis:PutRecord" + Resource: !Join + - ':' + - - arn:aws:kinesis + - !Ref AWS::Region + - !Ref AWS::AccountId + - !Sub stream/${AWS::StackName}-* +Outputs: + PolicyArn: + Description: StreamWriterPolicy2 + Value: !Ref StreamWriterPolicy2 \ No newline at end of file