Reputation: 1874
I'am using the below line in my template
"ec2instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"InstanceType" : {"Ref" : "Publicinstancetype"},
"ImageId" : "<myimageid>",
"SubnetId" : { "Fn::If" : ["createpublicsubnet",{"Ref":"publicsubnet"},
{"Fn::If" : ["createprivatesubnet",{"Ref":"privatesubnet"}]}
]}
}
} it is displaying as "Template error: Fn::If requires a list argument with three elements" where am I exactly going wrong? AWS documentations aren't helping. I have specified the conditions perfectly so no need top bother about it
Upvotes: 1
Views: 11192
Reputation: 3935
Since the Fn::If function requires 3 arguments, you need to use a pseudoparameter:
"ec2instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"InstanceType" : {"Ref" : "Publicinstancetype"},
"ImageId" : "<myimageid>",
"SubnetId" : {
"Fn::If" : [
"createpublicsubnet",
{"Ref" : "publicsubnet"},
{"Fn::If" : [
"createprivatesubnet",
{"Ref" : "privatesubnet"},
{"Ref" : "AWS::NoValue"} // Here
]}
]
}
}
}
Upvotes: 2
Reputation: 864
The Fn:In
requires 3 elements and you are giving only 2 parameters.
See the AWS documentation Example .
"SecurityGroups" : [{
"Fn::If" : [
"CreateNewSecurityGroup",
{"Ref" : "NewSecurityGroup"},
{"Ref" : "ExistingSecurityGroup"}
]
}]
"SubnetId" : { "Fn::If" : ["createpublicsubnet",{"Ref":"publicsubnet"},
It should have been "SubnetId" : { "Fn::If" : ["createpublicsubnet",{"Ref":"publicsubnet"}, {"Ref:"privatesubnet"}]}
In your code , it has only two elements been passed as .
Check the AWS documentation correctly. http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-conditions.html#intrinsic-function-reference-conditions-if
Upvotes: 3