Fn::Template for variable substitution

Registered by Steve Baker

A function Fn::Template which allows heat environment values to be inserted into string blocks like UserData scripts using a template substitution format.

There are many templating engines to choose from - probably simpler is better in this situation. One option is python Template Strings:
http://docs.python.org/2/library/string.html#template-strings

Having to escape $ with $$ shouldn't be too difficult for users.

  "/tmp/setup.mysql" : {
      "content" : { "Fn::Template" : { "Fn::Join" : ["\n", [
       "CREATE DATABASE $DBName",
       "GRANT ALL PRIVILEGES ON ${DBName}.* TO ${DBUsername}'@'localhost'",
       "IDENTIFIED BY '${DBPassword};",
       "FLUSH PRIVILEGES;",
       "EXIT"]]}}
      },

For YAML this would make it possible to build strings without Fn::Join, eg

/tmp/setup.mysql
  content
    Fn::Template: |-
       CREATE DATABASE $DBName
       GRANT ALL PRIVILEGES ON ${DBName}.* TO ${DBUsername}'@'localhost'
       IDENTIFIED BY '${DBPassword};
       FLUSH PRIVILEGES;
       EXIT

This is related to https://blueprints.launchpad.net/heat/+spec/bash-environment-function as it also addresses how values might be inserted into UserData scripts.

Also, this is similar to the Fn::Replace suggestion in that blueprint but without the requirement to explicitly declare substitutions:
  "/tmp/setup.mysql" : {
      "content" : { "Fn::Replace" : {"$DBName$", { "Ref" : "DBName"},
                                                    "$DBPassword$", { "Ref" : "DBPassword"},
                                                    "$DBUsername$", { "Ref" : "DBUsername"}},
                                                   { "Fn::Join" : ["\n", [
       "CREATE DATABASE $DBName$",
       "GRANT ALL PRIVILEGES ON $DBName$.* TO $DBUsername$'@'localhost'",
       "IDENTIFIED BY '$DBPassword$;",
       "FLUSH PRIVILEGES;",
       "EXIT"]]}}
      },

Blueprint information

Status:
Complete
Approver:
Steve Baker
Priority:
Medium
Drafter:
Steve Baker
Direction:
Approved
Assignee:
Steve Baker
Definition:
Approved
Series goal:
Accepted for havana
Implementation:
Implemented
Milestone target:
milestone icon 2013.2
Started by
Steve Baker
Completed by
Steve Baker

Related branches

Sprints

Whiteboard

Gerrit topic: https://review.openstack.org/#q,topic:bp/template-string-function,n,z

Addressed by: https://review.openstack.org/31736
    Add Fn::Variables template function.

Addressed by: https://review.openstack.org/32344
    Return empty string when Fn::Select target is None.

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.