The AWS::CloudFormation::Init documentation allows the specification of users to be created on ec2 instances, thusly:
"users" : {
"myUser" : {
"groups" : ["groupOne", "groupTwo"],
"uid" : "50",
"homeDir" : "/tmp"
}
}
What I'm trying to do is replace "myUser" programmatically. Using Ref: doesn't work:
"users": {
"{ "Ref": "UserName" }": {
"groups": [ "groupOne", "groupTwo" ]
}
}
It says "Template format error: JSON not well-formed." on the line with the Ref. I've tried about 800 different ways to type that, with and without quotation marks, using different functions instead of Ref, and I'm not getting anywhere. Unfortunately, I can't figure out how to diagnose if this is really just a "your missing a comma" kind of problem, or if there's a bigger issue with trying to programmatically replace the "myUser". And if it's the latter, what the solution is.
Any ideas?
Thanks!
This is not doable with
CloudFormation
service directly. The intrinsic functionRef
returns the value of the specified parameter or resource. The value can be then associated with the JSON/YAML key. But it can't be the key directly as JSON/YAML objects are written in key/value pairs.I have two ideas how you could resolve it:
CloudFormation
templates written inYAML
withJinja2
templating, sceptre or stacks projects can easily do thisEC2 user data
directly, you can try something like this: