【问题标题】:Why this Security Group is not being created in CloudFormation Stack?为什么未在 CloudFormation 堆栈中创建此安全组?
【发布时间】:2019-11-02 23:07:23
【问题描述】:

我正在尝试创建一个安全组并根据 Fn::If 内在函数对其进行命名。

Parameters:
  Environment:
    Type: String
    Description: Select Environment, Default is DEMO
    Default: DEMO
    AllowedValues: [ PROD, DEMO, QA, PERF, STAGING, INTEGRATION ]
Conditions:
  SGEnvironment: !Equals [!Ref Environment, PROD]

Resources:
  SG:
    Type: AWS::EC2::SecurityGroup
    Condition: SGEnvironment
    Properties:
      GroupName: !If [ SGEnvironment,"PROD-SG","NON-PROD-SG"]

安全组在条件为真时创建,但在条件为假时不创建。

只要选择了 PROD 以外的环境参数,就不会创建安全组。

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation aws-security-group


    【解决方案1】:

    如果你想一直创建SG,请删除Condition: SGEnvironment。使用Condition: SGEnvironment,行为与您提到的相同。

    1. SGEnvironment == PROD --> 创建 SG
    2. SGEnvironment != PROD --> 不创建 SG

    更多信息请参考here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-12
      • 2018-12-13
      • 2022-01-13
      • 1970-01-01
      • 2018-04-04
      • 1970-01-01
      • 1970-01-01
      • 2018-10-01
      相关资源
      最近更新 更多