Add a Fn::BashEnvironment function
The markup required to insert references to parameters or Fn:: calls into the UserData shell script is ugly and error-prone. An alternative is to add a function such as Fn::BashEnvironment that can be used to set up environment variables at the beginning of the script. After that, regular shell substitution can be used to actually reference the data.
You would use the function a bit like this (in JSON markup):
{ "Fn::BashEnviro
and it would expand to:
DB_
DB_
in the bash script.
The key to getting this right is to correctly escape any characters (especially double quotes) in the value that require escaping.
Blueprint information
- Status:
- Complete
- Approver:
- None
- Priority:
- Undefined
- Drafter:
- None
- Direction:
- Needs approval
- Assignee:
- None
- Definition:
- Superseded
- Series goal:
- None
- Implementation:
- Unknown
- Milestone target:
- None
- Started by
- Completed by
- Steve Baker
Whiteboard
Nice, a more general version might be Fn::Enviroment (no bash) as you could write your userdata in python/perl.
This works well for userdata, but less so for metadata as we are less in control of the execution of the files (and sometime they are not scripts but config).
How about a Fn::Replace as well?
From:
"/tmp/
"content" : { "Fn::Join" : ["", [
"CREATE DATABASE ", { "Ref" : "DBName" }, ";\n",
"GRANT ALL PRIVILEGES ON ", { "Ref" : "DBName" },
".* TO '", { "Ref" : "DBUsername" }, "'@'localhost'\n",
"IDENTIFIED BY '", { "Ref" : "DBPassword" }, "';\n",
"FLUSH PRIVILEGES;\n",
"EXIT\n"
]]},
"/tmp/
"content" : { "Fn::Replace" : {"$DBName$", { "Ref" : "DBName"},
"CREATE DATABASE $DBName$",
"GRANT ALL PRIVILEGES ON $DBName$.* TO $DBUsername$
"IDENTIFIED BY '$DBPassword$;",
"FLUSH PRIVILEGES;",
"EXIT"]]}}
},
This might look bettter in yaml - just an idea.
[ZB] A generic Fn::Environment might be difficult to implement - it would need to get the right syntax and escaping for every language - but I really like the Fn::Replace idea. I'd be inclined to do that instead of the BashEnvironment idea... generic is definitely better.
Gerrit topic: https:/
Addressed by: https:/
Add Fn::Variables template function.