如何在Cloudformation中使用嵌套列表或追加到列表? [英] How do I use nested lists or append to a list in Cloudformation?
问题描述
我想给这个资源2个安全组,这些安全组存在于堆栈外部,再加上一个作为堆栈的一部分而创建的安全组...
I want to give this resource 2 security groups that exist outside the stack, plus one that was created as part of the stack...
我尝试了以下操作,并收到错误消息:
I have tried the below and received the error:
属性SecurityGroups的值必须为字符串列表类型
Value of property SecurityGroups must be of type List of String
SecurityGroups:
- !FindInMap [ envMap, !Ref env, securityGroups ]
- !GetAtt SG.GroupId
供参考,这是我的地图
Mappings:
envMap:
qa:
"securityGroups":
- sg-xxxxxxxx
- sg-yyyyyyyy
这是资源
LoadBalancer:
Type: 'AWS::ElasticLoadBalancingV2::LoadBalancer'
Properties:
Name: !Join
- '-'
- - 'OR'
- 'ALB'
- !Ref env
Scheme: internal
SecurityGroups: !FindInMap [ envMap, !Ref env, securityGroups ]
Subnets: !FindInMap [ envMap, !Ref env, subnets ]
Type: application
IpAddressType: ipv4
这是我的固定代码
"securityGroups": 'sg-xxxxxx,sg-yyyyyy'
LoadBalancer:
Type: 'AWS::ElasticLoadBalancingV2::LoadBalancer'
Properties:
Name: !Join
- '-'
- - !Ref appname
- 'ALB2'
- !Ref env
Scheme: !FindInMap [ envMap, !Ref env, inorex ]
SecurityGroups: !Split
- ','
- !Join
- ','
- - !Ref SG
- !FindInMap [ envMap, !Ref env, securityGroups ]
Subnets: !FindInMap [ envMap, !Ref env, exsubnets ]
Type: application
IpAddressType: ipv4`
推荐答案
为了向Fn :: FindInMap函数提供的字符串值列表添加其他安全组,我们需要使用返回Fn :: FindInMap的值,并使用Fn :: Sub函数添加其他安全组.
In order to add an additional security group to the list of string values provided by Fn::FindInMap function we need to construct a new list of string values using the return value of Fn::FindInMap and add the additional security group using the Fn::Sub function.
Parameters:
env:
Default: qa
Type: String
Mappings:
envMap:
qa:
securityGroups: 'sg-xxxxxxxx,sg-xxxxxxxx'
sub:
subnets: 'subnet-xxxxxxxx,subnet-xxxxxxxx'
Resources:
LoadBalancer:
Type: 'AWS::ElasticLoadBalancingV2::LoadBalancer'
Properties:
Name: !Join
- '-'
- - OR
- ALB
- !Ref env
Scheme: internal
SecurityGroups: !Split
- ','
- !Sub
- 'sg-xxxxxxx,${mappedGroup}'
- mappedGroup: !FindInMap
- envMap
- !Ref env
- securityGroups
Subnets: !Split
- ','
- !FindInMap
- envMap
- sub
- subnets
Type: application
IpAddressType: ipv4
``
这篇关于如何在Cloudformation中使用嵌套列表或追加到列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!