>我有一个包含 2 个条件的 Cloudformation 模板
Conditions:
ProdEnvironment:
!Equals [ !Ref VPCStackNameParameter, 'ProductionVPC' ]
CertExists:
!Not [!Equals [!Ref SslCertificateArn, '']]
如何在要创建的资源中指定这两个条件?类似的东西
Resources:
Alb:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Condition: ProdEnvironment !And CertExists <--- this gives error!
您可以创建一个同时执行这两项操作的条件。
Conditions:
ProdEnvironment:
!Equals [ !Ref VPCStackNameParameter, 'ProductionVPC' ]
CertExists:
!Not [!Equals [!Ref SslCertificateArn, '']]
CertExistsAndProd: !And
- !Equals [ !Ref VPCStackNameParameter, 'ProductionVPC' ]
- !Not [!Equals [!Ref SslCertificateArn, '']]
Resources:
Alb:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Condition: CertExistsAndProd
文档似乎建议您还可以在条件中引用条件。因此,您也可以尝试:
Conditions:
ProdEnvironment:
!Equals [ !Ref VPCStackNameParameter, 'ProductionVPC' ]
CertExists:
!Not [!Equals [!Ref SslCertificateArn, '']]
CertExistsAndProd: !And
- !Condition ProdEnvironment
- !Condition CertExists
Resources:
Alb:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Condition: CertExistsAndProd