I came across an YAML Cloudformation template that was failing validation with the following error:
The !Contains function is part of AWS Service Catalog, and it is meant to give more control and flexibility when creating your company's stacks.
The challenge is that the current AWS Service Catalog documentation only provides examples in JSON format, leaving YAML users at their own luck.
Fiddling around in different forums, I happened to notice that YAML can recognize the JSON pattern of the Contains function ( 'Fn::Contains' )
Cannot convert the template because of an error:: unknown tag !<!Contains> at line...
The !Contains function is part of AWS Service Catalog, and it is meant to give more control and flexibility when creating your company's stacks.
The challenge is that the current AWS Service Catalog documentation only provides examples in JSON format, leaving YAML users at their own luck.
Fiddling around in different forums, I happened to notice that YAML can recognize the JSON pattern of the Contains function ( 'Fn::Contains' )
So in order to make the YAML code work, I replaced !Contains with 'Fn::Contains'
See the examples below:
JSON
"Rules": {
"AuroraDBInstanceTypeRule": {
"RuleCondition": {
"Fn::Equals": [
{
"Ref": "DBEngineType"
},
"Amazon Aurora"
]
},
"Assertions": [
{
"Assert": {
"Fn::Contains": [
[
"db.r3.large",
"db.r3.xlarge",
"db.r3.2xlarge",
"db.r3.4xlarge",
"db.r3.8xlarge",
"db.t2.small",
"db.t2.medium"
],
{
"Ref": "DBInstanceClass"
}
]
},
"AssertDescription": "Amazon Aurora does not currently support this DB instance class."
}
]
},
YAML
Rules:
AuroraDBInstanceTypeRule:
RuleCondition: !Equals
- !Ref DBEngineType
- Amazon Aurora
Assertions:
- Assert:
'Fn::Contains':
- - db.r3.large
- db.r3.xlarge
- db.r3.2xlarge
- db.r3.4xlarge
- db.r3.8xlarge
- db.t2.small
- db.t2.medium
- !Ref DBInstanceClass
AssertDescription: Amazon Aurora does not currently support this DB instance class.
Rules:
AuroraDBInstanceTypeRule:
RuleCondition: !Equals
- !Ref DBEngineType
- Amazon Aurora
Assertions:
- Assert:
'Fn::Contains':
- - db.r3.large
- db.r3.xlarge
- db.r3.2xlarge
- db.r3.4xlarge
- db.r3.8xlarge
- db.t2.small
- db.t2.medium
- !Ref DBInstanceClass
AssertDescription: Amazon Aurora does not currently support this DB instance class.
Comments
Post a Comment