2

I would want my CFT to take the list of subnets from the user as parameter and use that in create ALB subnets. How do I loop over subnets while creating the resource for ALB?

Something like:

    ApplicationLoadBalancer:
      Type: AWS::ElasticLoadBalancingV2::LoadBalancer
      Properties:
        Scheme: internet-facing # or internal
        Subnets:
<% for _, subnet in subnets %>
        - Ref: <%subnet%>
<% endfor %>
        SecurityGroups:
        - Ref: ELBSecurityGroup

1 Answer 1

2

Sadly, its not possible without custom resource or template macro. CloudFormation does not support loops unless you implement them yourself using the custom resource or macro.

You can also consider not using CloudFormation due to its limitations. Popular alternative is terraform, which has loops and could be used to achieve what you require.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.