/
Heat Template Tips

Heat Template Tips

Heat templates are a way of defining sets of resources in the cloud. These templates can help you manage groups of servers, volumes, ssh keys, networks and more. These groups of resources are called a Stacks. For an overview and documentation on the template structure, you can visit the links below. To view/create your own Stacks follow this link.

Template Overview

List of Resource Types and Examples

The template generator does not generate valid templates. You can use it to help generate a skeleton for a template, but expect to have to go back through and fix mistakes in the resources' keys/values.

Tips

  • Intrinsic functions are a great way to make templates more flexible. Use them to get parameters set by users (get_param), reference other resources from the template (get_resource and get_attr), dynamically construct strings (str_replace) and more.

  • Provide instances with scripts that run on boot using the user_data key.

### Script with no dynamic string replacement ### resources: the_server: type: OS::Nova::Server properties: # flavor, image etc user_data: | #!/bin/bash echo "Running boot script" # ...
###Takes user input for value of "foo" and uses that value as $FOO in the bootup script parameters: foo: default: bar resources: the_server: type: OS::Nova::Server properties: # flavor, image etc user_data: str_replace: template: | #!/bin/bash echo "Running boot script with $FOO" # ... params: $FOO: {get_param: foo}
  • To boot an instance from a volume or snapshot, used the block_device_mapping key and do not specify an image.

block_device_mapping: [{"snapshot_id": "snapshot-id-here", "device_name": "vda"}]

If you boot an instance from a snapshot this way, Heat will automatically create a volume from the snapshot and attach it to the instance. However, Heat will not automatically delete the volume when the stack is deleted. To get around this, you can define a volume in the template based on a snapshot and use that volume to boot the instance. This way, the volume is deleted with the rest of the resources when the stack is deleted.

 

Related content

Creating and Launching Instances from Snapshots
Creating and Launching Instances from Snapshots
More like this
Images
More like this