amazon-web-services - Cloudformation YAML 模板如果没有按预期工作
问题描述
我有 cloudformation 文件,用于检查是否是 Apple 添加 IP 以及添加其他 IP。
但是,我想为 Apple 而不是 Apple 添加 IP,而不将 IP 复制到它们两者。
只要写一次!
尝试执行此操作时,出现验证错误...
那是我的原始代码-
SecurityGroupIngress: !If
- IsApple
- - Description: "Its Apple IP"
FromPort: X
ToPort: X
IpProtocol: tcp
CidrIp: X.X.X.X
- - Description: "It's not Apple IP"
FromPort: X
ToPort: X
IpProtocol: tcp
CidrIp: X.X.X.X
这就是我想要的改变——
SecurityGroupIngress:
- Description: "Its *All* fruits IPs"
FromPort: X
ToPort: X
IpProtocol: tcp
CidrIp: X.X.X.X
!If
- IsApple
- - Description: "Its Apple IP"
FromPort: X
ToPort: X
IpProtocol: tcp
CidrIp: X.X.X.X
- - Description: "It's not Apple IP"
FromPort: X
ToPort: X
IpProtocol: tcp
CidrIp: X.X.X.X
解决方案
你应该移动你在!If
数组内SecurityGroupIngress
:
SecurityGroupIngress:
- Description: "Its *All* fruits IPs"
FromPort: X
ToPort: X
IpProtocol: tcp
CidrIp: X.X.X.X
- !If
- IsApple
- Description: "Its Apple IP"
FromPort: X
ToPort: X
IpProtocol: tcp
CidrIp: X.X.X.X
- Description: "It's not Apple IP"
FromPort: X
ToPort: X
IpProtocol: tcp
CidrIp: X.X.X.X
我没有测试过这个,但我认为上面应该可以工作。