sách gpt4 ai đã đi

aws-cloudformation - AWS CloudFormation - AWS::ElasticLoadBalancingV2::LoadBalancer - 安全组

In lại 作者:行者123 更新时间:2023-12-03 07:46:58 26 4
mua khóa gpt4 Nike

CFN 模板是否可以根据参数向 ALB 添加一些特定的安全组?

我遇到了两个安全组添加到 ALB 的情况:

ALB
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
...
SecurityGroups:
- !Ref 'SecurityGroup1'
- !Ref 'SecurityGroup2'

现在有一个 SecurityGroup3 ,仅当某些参数具有特定值时我才最终添加它。假设如果参数 add_sg3 bình đẳng yes,则将第三个 SG 添加到 ALB。我总是在类似情况下使用 "!If 但有超过 2 个 SG。欢迎任何建议。谢谢!

1 Câu trả lời

Bạn có thể sử dụngCondition来实现这一点和 AWS::NoValue伪参数。请遵循以下完整示例:

Các thông số:
Environment:
Type: String
Default: dev
AllowedValues: ["dev", "prod"]
VpcId:
Type: 'AWS::EC2::VPC::Id'
Subnet1:
Type: 'AWS::EC2::Subnet::Id'
Subnet2:
Type: 'AWS::EC2::Subnet::Id'

Conditions:
MyTest: !Equals ["dev", !Ref Environment]

Resources:
ALB:
Type: 'AWS::ElasticLoadBalancingV2::LoadBalancer'
Properties:
SecurityGroups:
- !Ref SecurityGroup1
- !If [ MyTest, !Ref SecurityGroup2, !Ref 'AWS::NoValue' ]
Subnets:
- !Ref Subnet1
- !Ref Subnet2

SecurityGroup1:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: 'Group 1'
VpcId: !Ref VpcId

SecurityGroup2:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: 'Group 2'
VpcId: !Ref VpcId

关于aws-cloudformation - AWS CloudFormation - AWS::ElasticLoadBalancingV2::LoadBalancer - 安全组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52976363/

26 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com