简体   繁体   English

为什么未在 CloudFormation Stack 中创建此安全组?

[英]Why this Security Group is not being created in CloudFormation Stack?

I am trying to create a Security Group and name it based on Fn::If intrinsic function.我正在尝试创建一个安全组并根据 Fn::If 固有 function 命名它。

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"]

Security Group is created whenever the condition is true but it does not get created when condition is false.安全组在条件为真时创建,但在条件为假时不会创建。

Security Group is not created whenever Environment Parameter is selected other than PROD.除了选择产品以外的其他环境参数时,不会创建安全组。

If you want to create SG all the time, please remove Condition: SGEnvironment .如果您想一直创建 SG,请删除Condition: SGEnvironment With Condition: SGEnvironment , the behaviour is same as what you mentioned.使用Condition: SGEnvironment ,行为与您提到的相同。

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

Please refer here for more information.请参阅此处了解更多信息。

Perfect, it worked as expected.完美,它按预期工作。 Thanks谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM