Reputation: 21
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
Upvotes: 1
Views: 3366
Reputation: 238299
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.
Upvotes: 2