gpt4 book ai didi

aws-cloudformation - AWS Cloudformation - 安全组 ID 列表导出和导入 - SecurityGroupIds 无效

转载 作者:行者123 更新时间:2023-12-03 07:38:56 27 4
gpt4 key购买 nike

我正在使用 2 个嵌套堆栈。我需要在 NestedB 中使用从 NestedA 导出的安全组 ID。导出的安全组 ID 将根据条件用于 NestedB 中的 SecurityGroupIds 属性。

但是,cloudformation 返回错误:属性验证失败:[属性值 {/LaunchTemplateData/SecurityGroupIds/0} 与类型 {String} 不匹配]

以下是我尝试过的片段:

嵌套A导出

Outputs:
SG1
Value: !Join
- ','
- - !Ref securitygroup1
- !Ref securitygroup2
Export:
Name: !Sub ${ExportVpcStackName}-SG1

SG2
Value: !Join
- ','
- - !Ref securitygroup3
- !Ref securitygroup4
Export:
Name: !Sub ${ExportVpcStackName}-SG2

父栈

Resources:
...
launchtemplate:
Type: AWS::Cloudformation::Stack
Properties:
TemplateURL: https://s3/nestedB.yaml
...
SG1:
Fn::ImportValue: !Sub ${ExportVpcStackName}-SG1
SG2:
Fn::ImportValue: !Sub ${ExportVpcStackName}-SG2

嵌套B导入

Parameters:
SG1
Type: List<AWS::EC2::SecurityGroup::Id>

SG2
Type: List<AWS::EC2::SecurityGroup::Id>

Resources:
launchtemplate:
Type: AWS::EC2::LaunchTemplate
Properties:
LaunchTemplateData:
...
SecurityGroupIds:
!If
- Condition1
-
- !Ref SG1
- !Ref SG2
- !If
- Condition2
-
- !Ref SG1
- !Ref AWS::NoValue

我还尝试将每个安全组直接/单独导入 NestedB,但没有成功,即:

嵌套A导出

Outputs:
securitygroup1:
Value: !Ref securitygroup1
Export:
Name: !Sub ${ExportVpcStackName}-securitygroup1

securitygroup2:
Value: !Ref securitygroup2
Export:
Name: !Sub ${ExportVpcStackName}-securitygroup2

securitygroup3:
Value: !Ref securitygroup3
Export:
Name: !Sub ${ExportVpcStackName}-securitygroup3

securitygroup4:
Value: !Ref securitygroup4
Export:
Name: !Sub ${ExportVpcStackName}-securitygroup4

嵌套B导入

Resources:
launchtemplate:
Type: AWS::EC2::LaunchTemplate
Properties:
LaunchTemplateData:
...
SecurityGroupIds:
!If
- Condition1
-
- Fn::ImportValue: !Sub ${ExportVpcStackName}-securitygroup1
- Fn::ImportValue: !Sub ${ExportVpcStackName}-securitygroup2
- Fn::ImportValue: !Sub ${ExportVpcStackName}-securitygroup3
- Fn::ImportValue: !Sub ${ExportVpcStackName}-securitygroup4
- !If
- Condition2
-
- Fn::ImportValue: !Sub ${ExportVpcStackName}-securitygroup1
- Fn::ImportValue: !Sub ${ExportVpcStackName}-securitygroup2
- !Ref AWS::NoValue

我犯了什么错误?

编辑:我已尝试@marcin建议,但仍然收到错误:

Property validation failure: [Value of property {/LaunchTemplateData/SecurityGroupIds/0} does not match type {String}]

最佳答案

而不是 Type: List<AWS::EC2::SecurityGroup::Id> ,请使用CommaDelimitedList .

还有你的SG1是 SG 的列表。您必须使用Fn::Select从列表中获取各个 SG 值。

关于aws-cloudformation - AWS Cloudformation - 安全组 ID 列表导出和导入 - SecurityGroupIds 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75128745/

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