Reputation: 11
I am creating a stack in AWS Cloudformation to build an EC2 Instance. Therefore I need certain parameters that the user should enter. My task is to choose between different types. Based on these types, the corresponding values are to be displayed in another list.
I thought I could solve this problem with the following code (Mappings included):
"Parameters": {
"ProjectName": {
"Description": "Enter the project name.",
"Type": "String"
},
"InstanceType": {
"Description": "Select your Instance type.",
"AllowedValues": [
"t3",
"m5",
"r5"
],
"Default": "t3",
"Type": "String"
},
"InstanceTypeSize": {
"Description": "Select your Instance type size.",
"AllowedValues":{
"Fn::Split" : [
",",
{ "Fn::FindInMap": [
"Params",
{"Ref": "InstanceType"},
"values"
]}
]
},
"Type": "String"
}
},
"Mappings": {
"Params": {
"t3": {
"values": "t3.nano,t3.micro,t3.small,t3.medium,t3.large,t3.xlarge,t3.2xlarge"
},
"m5": {
"values": "m5.large,m5.xlarge,m5.2xlarge,m5.4xlarge,m5.8xlarge,m5.12xlarge,m5.16xlarge,m5.24xlarge,m5.metal"
},
"r5": {
"values": "r5.large,r5.xlarge,r5.2xlarge,r5.4xlarge,r5.8xlarge,r5.12xlarge,r5.16xlarge,r5.24xlarge,r5.metal"
}
}
}
The Split
method returns a list of strings. The parameter "AllowedValues"
needs "an array containing the list of values allowed for the parameter".
Does anyone have any idea what I am doing wrong or where the error is? Is there possibly an alternative solution for the problem?
Upvotes: 1
Views: 3503
Reputation: 9625
Intrinsic Function Ref can't be used inside the Parameters
{ "Fn::FindInMap": [
"Params",
{"Ref": "InstanceType"},
"values"
]}
You have to define the instance types as one big array
"Parameters": {
"ProjectName": {
"Description": "Enter the project name.",
"Type": "String"
},
"InstanceType": {
"Description": "Select your Instance type.",
"AllowedValues": [t3.nano,t3.micro,t3.small,t3.medium,t3.large,t3.xlarge,t3.2xlarge,m5.large,m5.xlarge,m5.2xlarge,m5.4xlarge,m5.8xlarge,m5.12xlarge,m5.16xlarge,m5.24xlarge,m5.metal,r5.large,r5.xlarge,r5.2xlarge,r5.4xlarge,r5.8xlarge,r5.12xlarge,r5.16xlarge,r5.24xlarge,r5.metal
],
"Default": "t3",
"Type": "String"
},
"InstanceTypeSize": {
"Description": "Select your Instance type size.",
"AllowedValues":{
"Fn::Split" : [
",",
{ "Fn::FindInMap": [
"Params",
{"Ref": "InstanceType"},
"values"
]}
]
},
"Type": "String"
}
}
Upvotes: 2