Reputation: 1441
I have a cloudformation template that uses a few ssm parameters. Those parameters are only defined in a given region for a given account. I would like to use the ssm parameters if they are defined and not use them if they are not defined in a given region (perhaps default to a certain string value like "undefined").
Something like this
Parameters:
anssmparameter:
Type: AWS::SSM::Parameter::Value<String>
# if ssmparam is defined
Default: ssmparam
# else ssmparam is not defined use a different default
Default: "a placeholder value"
Description: some description
Is this possible in cloudformation? I have researched a bit and it seems this is not possible?
The close I have seen is this which essentially says it is not possible
Is this possible to have optional SSM parameter?
Upvotes: 2
Views: 1604
Reputation: 11
You can use dynamic references to resolve on runtime if given parameter value
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html
Parameters:
anssmparameter:
Type: String
placeholdervalue:
Type: String
Default: 'a placeholder value'
Conditions:
toResolveSSMParam: !Not [!Equals [!Sub '${anssmparameter}', '']]
Resources:
ResourceA:
Properties:
PropertyA: !If [toResolveSSMParam, !Sub '{{resolve:ssm:${anssmparameter}}}', !Ref placeholdervalue]
Upvotes: 1
Reputation: 238209
Sadly, you can't have conditions in Parameters
, unless you write a tin wrapper around your deployment procedure which would modify the template before it goes to CloudFormation.
Other then that, you would have to use If
conditions in Resources
to actually alternate between different possibilities.
Upvotes: 1