There are a number of functions that you can use to help you write CloudFormation compatible templates. While most CloudFormation functions are supported in HOT version ‘2013-05-23’, Fn::Select is the only CloudFormation function supported in HOT templates since version ‘2014-10-16’ which is introduced in Juno.
All of these functions (except Ref) start with Fn::.
Returns the value of the named parameter or resource.
The name of the resource or parameter.
{Ref: my_server}
Returns the nova instance ID. For example, d8093de0-850f-4513-b202-7979de6c0d55
.
This is a placeholder for a function to convert an input string to Base64. This function in Heat actually performs no conversion. It is included for the benefit of CFN templates that convert UserData to Base64. Heat only accepts UserData in plain text.
The string to convert.
{"Fn::Base64": "convert this string please."}
Returns the original input string.
Returns the value corresponding to keys into a two-level map declared in the Mappings section.
The logical name of a mapping declared in the Mappings section that contains the keys and values.
The top-level key name. It’s value is a list of key-value pairs.
The second-level key name, which is set to one of the keys from the list assigned to top_level_key.
Mapping:
MyContacts:
jone: {phone: 337, email: a@b.com}
jim: {phone: 908, email: g@b.com}
{"Fn::FindInMap": ["MyContacts", "jim", "phone" ] }
Returns 908
.
Returns an attribute of a resource within the template.
The name of the resource.
The name of the attribute.
{Fn::GetAtt: [my_server, PublicIp]}
Returns an IP address such as 10.0.0.2
.
Returns the Availability Zones within the given region.
Note: AZ’s and regions are not fully implemented in Heat.
The name of the region.
{Fn::GetAZs: ""}
Returns the list provided by nova availability-zone-list
.
Like python join, it joins a list of strings with the given delimiter.
The string to join the list with.
The list to join.
{Fn::Join: [",", ["beer", "wine", "more beer"]]}
Returns beer, wine, more beer
.
Select an item from a list.
Heat extension: Select an item from a map
The number of item in the list or the name of the item in the map.
The collection to select the item from.
For a list lookup:
{ "Fn::Select" : [ "2", [ "apples", "grapes", "mangoes" ] ] }
Returns mangoes
.
For a map lookup:
{ "Fn::Select" : [ "red", {"red": "a", "flu": "b"} ] }
Returns a
.
This is the reverse of Join. Convert a string into a list based on the delimiter.
Matching string to split on.
The string to split.
{ "Fn::Split" : [ ",", "str1,str2,str3,str4"]}
Returns {["str1", "str2", "str3", "str4"]}
.
Find and replace one string with another.
A map of substitutions.
The string to do the substitutions in.
{"Fn::Replace": [
{'$var1': 'foo', '%var2%': 'bar'},
'$var1 is %var2%'
]}
Returns "foo is bar"
.
user writes a template that will fill in for a resource (the resource is the facade).
when they are writing their template they need to access the metadata from the facade.
One of Metadata
, DeletionPolicy
or UpdatePolicy
.
{'Fn::ResourceFacade': 'Metadata'}
{'Fn::ResourceFacade': 'DeletionPolicy'}
{'Fn::ResourceFacade': 'UpdatePolicy'}
Here is a top level template top.yaml
resources:
my_server:
type: OS::Nova::Server
metadata:
key: value
some: more stuff
Here is a resource template my_actual_server.yaml
resources:
_actual_server_:
type: OS::Nova::Server
metadata: {'Fn::ResourceFacade': Metadata}
The environment file env.yaml
resource_registry:
resources:
my_server:
"OS::Nova::Server": my_actual_server.yaml
To use it
$ openstack stack create -t top.yaml -e env.yaml mystack
What happened is the metadata in top.yaml
(key: value, some: more
stuff) gets passed into the resource template via the Fn::ResourceFacade
function.
Convert an AWS style member list into a map.
The name of the key (normally “Name” or “Key”).
The name of the value (normally “Value”).
The string to convert.
{'Fn::MemberListToMap': ['Name', 'Value', ['.member.0.Name=key',
'.member.0.Value=door',
'.member.1.Name=colour',
'.member.1.Value=green']]}
Returns {'key': 'door', 'colour': 'green'}
.
Compares whether two values are equal. And returns true if the two values are equal or false if they aren’t.
A value of any type that you want to compare.
A value of any type that you want to compare.
{'Fn::Equals': [{'Ref': 'env_type'}, 'prod']}
Returns true if the param ‘env_type’ equals to ‘prod’, otherwise returns false.
Returns one value if the specified condition evaluates to true and another value if the specified condition evaluates to false.
A reference to a condition in the Conditions
section.
A value to be returned if the specified condition evaluates to true.
A value to be returned if the specified condition evaluates to false.
{'Fn::If': ['create_prod', 'value_true', 'value_false']}
Returns ‘value_true’ if the condition ‘create_prod’ evaluates to true, otherwise returns ‘value_false’.
Acts as a NOT operator.
The syntax of the Fn::Not
function is
{'Fn::Not': [condition]}
Returns true for a condition that evaluates to false or returns false for a condition that evaluates to true.
A condition such as Fn::Equals
that evaluates to true or false
can be defined in this function, also we can set a boolean value
as a condition.
{'Fn::Not': [{'Fn::Equals': [{'Ref': env_type'}, 'prod']}]}
Returns false if the param ‘env_type’ equals to ‘prod’, otherwise returns true.
Acts as an AND operator to evaluate all the specified conditions. Returns true if all the specified conditions evaluate to true, or returns false if any one of the conditions evaluates to false.
A condition such as Fn::Equals that evaluates to true or false.
{'Fn::And': [{'Fn::Equals': [{'Ref': env_type}, 'prod']},
{'Fn::Not': [{'Fn::Equals': [{'Ref': zone}, 'beijing']}]}]
Returns true if the param ‘env_type’ equals to ‘prod’ and the param ‘zone’ is not equal to ‘beijing’, otherwise returns false.
Acts as an OR operator to evaluate all the specified conditions. Returns true if any one of the specified conditions evaluate to true, or returns false if all of the conditions evaluates to false.
A condition such as Fn::Equals that evaluates to true or false.
{'Fn::Or': [{'Fn::Equals': [{'Ref': zone}, 'shanghai']},
{'Fn::Equals': [{'Ref': zone}, 'beijing']}]}
Returns true if the param ‘zone’ equals to ‘shanghai’ or ‘beijing’, otherwise returns false.
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.