【问题标题】:Cloudformation YAML template if else not working as expectedCloudformation YAML 模板如果没有按预期工作
【发布时间】:2021-10-17 17:55:11
【问题描述】:

我有 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

【问题讨论】:

    标签: amazon-web-services syntax yaml ip amazon-cloudformation


    【解决方案1】:

    您应该将 !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
    

    我还没有测试过,但我认为上面应该可以工作。

    【讨论】:

      猜你喜欢
      • 2021-01-31
      • 2020-03-22
      • 2015-08-02
      • 2012-04-12
      • 2017-07-17
      • 1970-01-01
      • 2013-04-12
      相关资源
      最近更新 更多