How to deploy an instance (VM) with OSC - Ansible or Terraform

OpenStack Client (also known as OSC) is a command-line client for OpenStack that consolidates the command set for Compute, Identity, Image, Object Storage, and Block Storage APIs into a single shell with a unified command structure.

This chapter includes examples of how to deploy a VM using OCS, Ansible, or with Terraform.

Prerequisites

  • The CLI used (OSC, Ansible or Terraform) must be installed and configured
  • Basic knowledge of the Linux operating system (shell)
  • Access to running Linux VM (In our example Ubuntu) with open port (Egress 443) to OpenStack API
  • Application Credentials (cloud.yaml)

A guide to installing and configuring the OpenStack OSC (see: How to configure the OpenStack Client (OSC)).

In the following examples, a VM running Ubuntu 20.04 is deployed to the Availability ZONE ch-zh1-az2.

Example deploy VM with OpenStack CLI (OSC)

openstack server create vm-u2004-az2 \
   --image "Ubuntu 20.04" \
   --flavor m1.small \
   --key-name foo-key \
   --network foo-net \
   --security-group default \
   --availability-zone ch-zh1-az2

Example deploy VM with Ansible

- os_server:
    name: "foo-u2004-az2"
    image: "Ubuntu 20.04"
    key_name: "foo-key"
    flavor: "m1.micro"
    network: "foo-net"
    security_groups: "default"
    availability_zone: "ch-zh1-az2"

Example deploy VM with Terraform

resource "openstack_compute_instance_v2" "instance_1" {
   name = "vm-u2004-az2"
   image_name = "Ubuntu 20.04"
   flavor_name = "m1.micro"
   key_pair = "foo-key"
   security_groups = ["default"]
   availability_zone = "ch-zh1-az2"

   network {
      name = "foo-net"
   }
}

How to deploy a volume with OSC - Ansible or Terraform

In the following examples, a 10GB volume is deployed to the Availability ZONE ch-zh1-az2.

Example deploy volume with OpenStack CLI (OSC)

openstack volume create vol1-az2 \
   --size 10 \
   --availability-zone ch-zh1-az2

Example deploy volume with Ansible

- os_volume:
    display_name: "vol1-az2"
    size: 10
    availability_zone: "ch-zh1-az2"

Example deploy volume with Terraform

resource "openstack_blockstorage_volume_v2" "volume_1" {
   name = "vol1-az2"
   size = 10
   availability_zone = "ch-zh1-az2"