Heat template examples
A Heat template is a valid Heat Orchestration Template (HOT), as defined in the OpenStack HOT specification.
- The introduction and some basic examples at http://docs.openstack.org/developer/heat/template_guide/hot_guide.html
- The Heat Orchestration Template specification at http://docs.openstack.org/developer/heat/template_guide/hot_spec.html
- The OpenStack Resource Types and the related parameters at http://docs.openstack.org/developer/heat/template_guide/openstack.html
When developing a template, it is recommended to use parameters and to avoid hardcoded values.
In the following examples, Example 1 and Example 2 are taken from the OpenStack Template Guide and show the differences in using hardcoded values or parameters.
- SCOIMAGE
- Lookup of images from the image repository for the region.
- SCOFLAVOR
- Lookup of flavor size from the selection available in the region.
- SCONETWORK
- Lookup of available networks in the region.
- SCOKEY
- Lookup of the registered keys for the project.
Example 4 shows how to set the admin password for a virtual machine by using the user_data section.
Example 5 shows how to deploy an AIX or Linux on Power® server on PowerVC where you specify the Storage Connectivity Group to use and the Storage Template on which the boot volume is placed.
Example 1
heat_template_version: 2013-05-23
description: Simple template to deploy a single compute instance with hardcoded values
resources:
my_instance:
type: OS::Nova::Server
properties:
key_name: my_key_pair_1
image: cirros-0.3.1-x86_64
flavor: m1.tiny
Example 2
heat_template_version: 2013-05-23
description: Simple template to deploy a single compute instance with parameters
parameters:
key_name:
type: string
label: Key Name
description: Name of key-pair to be used for compute instance
image_id:
type: string
label: Image ID
description: Image to be used for compute instance
instance_type:
type: string
label: Instance Type
description: Type of instance (flavor) to be used
resources:
my_instance:
type: OS::Nova::Server
properties:
key_name: { get_param: key_name }
image: { get_param: image_id }
flavor: { get_param: instance_type }
Example 3
heat_template_version: 2013-05-23
description: Simple template to deploy a stack with two virtual machine instances
parameters:
image_name_1:
type: string
label: Image Name
description: SCOIMAGE Specify an image name for instance1
default: cirros-0.3.1-x86_64
image_name_2:
type: string
label: Image Name
description: SCOIMAGE Specify an image name for instance2
default: cirros-0.3.1-x86_64
network_id:
type: string
label: Network ID
description: SCONETWORK Network to be used for the compute instance
resources:
my_instance1:
type: OS::Nova::Server
properties:
image: { get_param: image_name_1 }
flavor: m1.small
networks:
- network : { get_param : network_id }
my_instance2:
type: OS::Nova::Server
properties:
image: { get_param: image_name_2 }
flavor: m1.tiny
networks:
- network : { get_param : network_id }
Example 4
heat_template_version: 2013-05-23
description: Simple template to set the admin password for a virtual machine
parameters:
key_name:
type: string
label: Key Name
description: SCOKEY Name of the key pair to be used for the compute instance
image_name:
type: string
label: Image Name
description: SCOIMAGE Name of the image to be used for the compute instance
password:
type: string
label: password
description: admin password
hidden: true
resources:
my_instance:
type: OS::Nova::Server
properties:
key_name: { get_param: key_name }
admin_user: sampleuser
image: { get_param: image_name }
flavor: m1.small
user_data:
str_replace:
template: |
#!/bin/bash
echo "Setting password to " $password
echo $password |passwd --stdin sampleuser
params:
$password: { get_param: password }
Example 5
The following example is a simple Heat template to deploy an AIX or Linux on Power server on PowerVC where you specify the Storage Connectivity Group to use and the Storage Template on which the boot volume is deployed:
heat_template_version: 2013-05-23
description: Template to Deploy on NPIV v7k storage only
parameters:
network_id1:
type: string
description: SCONETWORK ID of the (nova) network a server should be deployed to.
flavor_id:
type: string
description: SCOFLAVOR The flavor to be applied to the server DatabaseTierVM.
image:
type: string
label: Image
description: SCOIMAGE The Image to be deployed
resources:
heat:
type: OS::Nova::Server
properties:
image: { get_param: image }
flavor: { get_param: flavor_id }
availability_zone: D0EB
metadata: { selected-scg: d91acbbe-3d81-4279-b389-54b3ad4a1c8c, selected-storage-template: 0431b2f3-fea6-4aa5-b3fb-d0e82ccf5ebb }
networks:
- network : { get_param : network_id1 }