2
Licensed under the Apache License, Version 2.0 (the "License"); you may
3
not use this file except in compliance with the License. You may obtain
4
a copy of the License at
6
http://www.apache.org/licenses/LICENSE-2.0
8
Unless required by applicable law or agreed to in writing, software
9
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11
License for the specific language governing permissions and limitations
20
When writing complex templates you are encouraged to break up your
21
template into separate smaller templates. These can then be brought
22
together using template resources. This is a mechanism to define a resource
23
using a template, thus composing one logical stack with multiple templates.
26
How to use template resources for composition
27
---------------------------------------------
29
Template resources do a very similar job to
30
AWS::CloudFormation::Stack, but they are more powerful as they allow a
31
template to "stand in for" any resource type.
33
Template resources can be used to do the following:
35
* Define new resource types (make you own resource library).
36
* Override the default behaviour of existing resource types.
38
The way this is achieved is:
40
* The heat client gets the associated template files and passes them
41
along in the "files" section of the "POST stacks/".
42
* The environment in Orchestration engine manages the mapping of resource type
44
* Translation of the template parameters into resource properties.
46
Let's go through some examples. In all examples assume the
47
same resource template. This is a simple wrapper around a nova server
52
heat_template_version: 2013-05-23
56
description: Name of a KeyPair
59
type: OS::Nova::Server
61
key_name: {get_param: key_name}
63
image: the_one_i_always_use
69
In this example you will not map a resource type name at all, but
70
directly specify the template URL as the resource type.
72
Your main template (main.yaml) would look like this.
76
heat_template_version: 2013-05-23
83
Some notes about URLs:
85
The above reference to my_nova.yaml assumes it is in the same directory.
86
You could use any of the following forms:
88
* Relative path (type: my_nova.yaml)
89
* Absolute path (type: file:///home/user/templates/my_nova.yaml)
90
* Http URL (type: http://example.com/templates/my_nova.yaml)
91
* Https URL (type: https://example.com/templates/my_nova.yaml)
94
To create the stack, run::
96
$ heat stack-create -f main.yaml example-one
101
In this example you will use the environment (env.yaml) to override the
102
OS::Nova::Server with my_nova to get the defaults you want.
107
"OS::Nova::Server": my_nova.yaml
109
A more detailed discussion on this can be found here :ref:`environments`
111
Now you can use "OS::Nova::Server" in our top level template (main.yaml).
117
type: OS::Nova::Server
121
To create the stack, run::
123
$ heat stack-create -f main.yaml -e env.yaml example-two
126
Getting access to nested attributes
127
-----------------------------------
128
There are implicit attributes of a template resource. These are
129
accessable as follows:
133
heat_template_version: 2013-05-23
140
value: {get_attr: my_server, resource.server, first_address}
143
Making your template resource more "transparent"
144
------------------------------------------------
145
If you wish to be able to return the ID of one of the inner resources
146
instead of the nested stack's ARN, you can add the following special
147
output to your template resource.
153
type: OS::Nova::Server
157
value: {get_resource: server}
159
Now when you use "get_resource" or "get_attr" from the outer template heat
160
will use nova server and not the template resource.