我对AWS CloudFormation如何对待布尔值和布尔值的字符串感到困惑。
例如,就CloudFormation而言,'true'
和true
(或'false'
和false
)在逻辑上是否等效?我在“快速入门”模板中看到了这两种情况的示例,这些示例使我认为它们是正确的(即使我还没有找到这种或另一种方式的文档)。
例如,在模板quickstart-compliance-common/templates/vpc-production.template中,他们定义了类型为“字符串”的变量pSupportsNatGateway
(即使其默认值为 literal 值{ {1}}):
true
然后,在模板的condition中,将该参数(可能是字符串)与 literal 值Parameters:
...
pSupportsNatGateway:
Description: Specifies whether this region supports NAT Gateway (this value is
determined by the main stack if it is invoked from there)
Type: String
Default: true
进行比较。
true
我的问题是,CloudFormation如何比较文字值和这些值的字符串? AWS文档中的何处定义?
答案 0 :(得分:0)
我不知道在哪里记录,但是是!显然,就CloudFormation而言,文字布尔值(或数字)及其字符串值是等效的。
我创建了一个最小的CloudFormation模板来对此进行测试:
---
AWSTemplateFormatVersion: 2010-09-09
Description: Test CloudFormation template
Parameters:
pCreateCluster:
Description: To create or not create?
Type: String
Default: 'true'
AllowedValues:
- 'true'
- 'false'
Conditions:
CreateClusterConditionTrue1:
!Equals
- !Ref pCreateCluster
- 'true'
CreateClusterConditionTrue2:
!Equals
- !Ref pCreateCluster
- true
CreateClusterConditionFalse1:
!Equals
- !Ref pCreateCluster
- 'false'
CreateClusterConditionFalse2:
!Equals
- !Ref pCreateCluster
- false
Resources:
rFargateCluster:
Type: AWS::ECS::Cluster
Condition: CreateClusterConditionTrue1
Properties:
ClusterName: "my-test-cluster"
Outputs:
CreateClusterConditionTrue1:
Value:
!If
- CreateClusterConditionTrue1
- "The answer is True"
- "The answer is False"
CreateClusterConditionTrue2:
Value:
!If
- CreateClusterConditionTrue2
- "The answer is True"
- "The answer is False"
CreateClusterConditionFalse1:
Value:
!If
- CreateClusterConditionFalse1
- "The answer is True"
- "The answer is False"
CreateClusterConditionFalse2:
Value:
!If
- CreateClusterConditionFalse2
- "The answer is True"
- "The answer is False"
...
结果表明它们实际上是等效的:
Key Value
CreateClusterConditionTrue1 The answer is True
CreateClusterConditionTrue2 The answer is True
CreateClusterConditionFalse2 The answer is False
CreateClusterConditionFalse1 The answer is False