gpt4 book ai didi

list - 如何在 Cloudformation 中使用嵌套列表或附加到列表?

转载 作者:行者123 更新时间:2023-12-03 07:21:22 25 4
gpt4 key购买 nike

我想为该资源提供 2 个存在于堆栈外部的安全组,加上一个作为堆栈一部分创建的安全组...

我已尝试以下操作并收到错误:

Value of property SecurityGroups must be of type List of String

SecurityGroups: 
- !FindInMap [ envMap, !Ref env, securityGroups ]
- !GetAtt SG.GroupId

作为引用,这是我的 map

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 函数。

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
``

关于list - 如何在 Cloudformation 中使用嵌套列表或附加到列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49035760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com