Terraform

Terraform is an open source tool from HashiCorp that can be used to create and manage application infrastructure. Terraform can also provide software for example with Ansible or Chef.

Provider

  • Create a modules.tf file and define the OpenStack provider (https://www.terraform.io/docs/providers/openstack/index.html)

    provider "openstack" {
      user_name   = "USERNAME"
      password    = "PASSWORD"
      auth_url    = "https://api-1.betacloud.io:5000/v3"
      region      = "betacloud-1"
    }
    
    module "sample" {
      source = "modules/sample"
    }
    
  • Or create a clouds.yaml and secure.yaml file (see Authentication chapter)

    provider "openstack" {
      cloud = "sample"
    }
    
    module "sample" {
      source = "modules/sample"
    }
    
  • Create a modules directory

    $ mkdir -p modules/sample
    

Resources

Variables

  • Create a variables.tf file below the sample module directory

    variable "network" {
      default  = "sample"
    }
    
    variable "pool" {
      default  = "public"
    }
    
    variable "flavor" {
      default  = "1C-1GB-10GB"
    }
    
    variable "image" {
      default  = "Ubuntu 18.04"
    }
    

Start the deployment

First we initialize the working directory with the terraform init command after writing a new Terraform configuration. This will ensure that Terraform has all the necessary components to build the template in OpenStack.

If the working directory is initialized, we create an execution plan with terraform plan. In this step, the required resources are compared with the state information stored by Terraform.

After checking the plan, the configuration can be carried out with terraform apply. The instance can easily be deleted using the terraform destroy command.