Reputation: 107
How to share the allowed values of one parameter with another parameter in aws cloudformation template as they are duplicates. Please refer the below snippet.
"Parameters": {
"mymasterinstance": {
"Description" : "My master instance",
"Type": "String",
"Default" : "t2.micro",
"AllowedValues": ["t2.micro","t2.small","t2.large","t2.xlarge"]
},
"myslaveinstance": {
"Description": "My slave instance",
"Type" :"String",
"Default": "t2.micro",
"AllowedValues" : ["t2.micro","t2.small","t2.large","t2.xlarge"]
},
},
I want to share the AllowedValues of mymasterinstance with myslaveinstance. Anyone please help on this.
Upvotes: 0
Views: 458
Reputation: 4987
I am not sure if I understood your problem well, but I guess you want to define those instance types values once, and use it everywhere. If that is the issue, you can't by plain yaml/json templates.
You can try defining your configuration data in a plain text file, and using a templating language, e.g. we use jinja2, read those values wherever you need.
In my company, we are heavily using jinja2 for automating big part of our templates. Doing so, you may end up having something like this:
template.json.jinja
"Parameters": {
"mymasterinstance": {
"Description" : "My master instance",
"Type": "String",
"Default" : "t2.micro",
"AllowedValues": "{{ instance_allowed_values }}"
},
"myslaveinstance": {
"Description": "My slave instance",
"Type" :"String",
"Default": "t2.micro",
"AllowedValues" : "{{ instance_allowed_values }}"
},
}
vars.json
{
"instance_allowed_values": ["t2.micro","t2.small","t2.large","t2.xlarge"]
}
Note: jinja is a python templating language. Depending on your project nature, you may choose different tool to do the preprocessing job.
Upvotes: 1