IBM Cloud Orchestrator, Version 2.5.0.8

Heat template examples

A Heat template is a valid Heat Orchestration Template (HOT), as defined in the OpenStack HOT specification.

For detailed information about the Heat Orchestration Templates, see the OpenStack Template Guide at http://docs.openstack.org/developer/heat/template_guide/. In the guide, you can find the following information: The Heat Orchestration Templates are under development, so the OpenStack Template Guide is periodically updated by the community.

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.

Example 3 shows how to use lookup annotation to generate a list of possible values for a parameter, which helps the user to select a valid parameter value. The following lookup annotations are supported:
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.

Note: Heat Orchestration Templates are sensitive to formatting issues. To avoid template validation errors, use the correct indentation.

Example 1

The following example is a simple Heat template to deploy a single virtual system and it is limited to a single combination of image, key, and flavor values that are hardcoded in the template:
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

The following example is a Heat template to deploy a single virtual system with parameters and it is therefore reusable for other configurations:
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

The following example is a simple Heat template to deploy a stack with two virtual machine instances by using lookup annotations for parameters:
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

The following example is a simple Heat template to set the admin password for a virtual machine by using the user_data section:
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 }
Note: You can create the availability zones for a PowerVM® server by using the Host Aggregates panel in the OpenStack Dashboard. Ensure that, if you created new availability zones, they are then added to the relevant domains and projects before attempting to use them. selected-scg (Storage Connectivity Group) and selected-storage-template can be found from the Image_topology of the image you are planning to use. On the OpenStack Controller, run the glance image-show <image id> command. Image Topology specifies which Storage Connectivity Group and which Storage Templates are supported by that specific image.