Create a Heat stack

Heat is an orchestration component of OpenStack which allows templates to be used to define resources and to specify the relationships between resources in a stack. This page explains the basics of how to create a heat stack. For more detailed docs and examples, see the Heat Advanced Material pages at https://stfc.atlassian.net/wiki/spaces/CLOUDKB/pages/211845365 .

To check Heat is available we can run the command:

openstack stack list

This command returns the list of stacks in the user’s project. If no stacks have been created, this command returns an empty line. If Heat is not installed, see the more detailed pages on Heat: https://stfc.atlassian.net/wiki/spaces/CLOUDKB/pages/211845365

To create a stack, we first need to write a template which will be used to launch the stack.

Templates

Templates are used to define the resources which should be created as part of a stack and the relationships between resources. With the integration of other OpenStack components, Heat Templates allow the create of most OpenStack resource types. This includes infrastructure resources such as instances, databases, security groups, users, etc. The Heat Orchestration Template (HOT) is native to OpenStack for creating stacks. These templates are written in YAML.

Heat Orchestration Templates

The structure of a Heat Orchestration Template is given as follows:

heat_template_version: 2018-08-31 #OpenStack Version we want to use. #Here, we want to use template for the Rocky release onwards description: #description of the template parameter_groups: #declares the parameter group and order. #This is not a compulsory section, however it is useful for grouping #parameters together when building more complex templates. parameters: #declares the parameters for resources resources: #declares the template resources # e.g. alarms, floating IPs, instances etc. outputs: #declares the output of the stack conditions: #declares any conditions on the stack

heat_template_version

This tells heat which format and features will be supported when creating the stack.

For example:

heat_template_version: 2018-03-02

Indicates that the Heat Template contains features which have been added and/or removed up to the Queens release of OpenStack.

The template version:

Indicates that the Heat Template contains features which have been added and/or removed up to the Rocky release of OpenStack. For templates being used in the current release of OpenStack, heat uses Queen’s templates is used.

A list of template versions can be found here: https://docs.openstack.org/heat/train/template_guide/hot_spec.html#heat-template-version

parameter_groups

Parameter groups indicate how the input parameters are grouped. The order of the parameters are given in lists. This section is not strictly compulsory for launching stacks, however it is useful for more complex templates where there are several input parameters to be used.

The syntax for parameter_groups is:

Parameters

The parameters section specifies the input parameters that have to be provided when the template is initalised. The syntax for parameters is of the form:

Resources

This is a compulsory section and must contain at least one resource. This could be an instance, floating IP, Network, key pair, etc.

A list of the different OpenStack resources which can be used in a Heat template can be found here: https://docs.openstack.org/heat/latest/template_guide/openstack.html

Below is an example of the resource section for an instance.

Outputs

Outputs define the parameters that should be available to the user after a stack has been created. This would be, for example, parameters such as the IP addresses of deployed instances, or the URL of web applications deployed as a stack. Each output is defined as a separate block within the outputs section:

Conditions

The conditions section in the heat template defines at least one condition that is evaluated based on the input parameter values when a user creates or updates a stack. The conditions can be associated with resources, the properties of the resources and the output.

The syntax for conditions in the heat template is given by:

Example Template

The following template (example-template.yaml) is for a stack containing a single instance.

Using a template similar to this one, we can launch a stack.

Create a Stack

Stacks can be launched using the OpenStack CLI. The syntax for creating a stack is:

For example, to create a stack using the template example-template.yaml:

This should return something similar to the following:

Then the status of the stack can be checked using the command:

Delete a Stack

To delete a stack, use the command:

Note: Any resources such as instances which have been created specifically for the stack will also be deleted.

Further Reading

For more detailed information on Heat, and to see some example stacks, refer to the advance Heat docs at https://stfc.atlassian.net/wiki/spaces/CLOUDKB/pages/211845365

References