amazon-web-services - 为什么没有在 CloudFormation Stack 中创建此安全组?

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

我正在尝试创建一个安全组并根据 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 时,都不会创建安全组。

最佳答案

如果您想一直创建SG,请删除条件:SGEnvironment。对于条件:SGEnvironment,行为与您提到的相同。

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

请引用here了解更多信息。

关于amazon-web-services - 为什么没有在 CloudFormation Stack 中创建此安全组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58671511/

相关文章:

amazon-web-services - 内部负载均衡器的 AWS Route 53 DNS 别名

amazon-s3 - 如何修复 AWS CloudFormation 中的 "Unable to validate the following destination configurations"?

amazon-web-services - 找到用于创建 cloudformation 堆栈的模板

amazon-web-services - AWS VPC 安全组命名约定

amazon-web-services - AWS VPC 安全组中的规则数是如何计算的?

java - java中的AWS Lambda函数

amazon-web-services - 如何使用Docker播种的Cloudformation编写AWS VPC脚本

amazon-web-services - 本地镜像大小和 ECR 图像大小不同 - 为什么?

amazon-web-services - 无法在 Cloudformation 模板中为 Cloudwatch 警报定义数学表达式

amazon-web-services - 如何使用模板在cloudformation中添加多个安全组和组名称?