YJWANG

[Terraform] OpenStack Provider (v 0.14.x) 본문

91.IaC

[Terraform] OpenStack Provider (v 0.14.x)

왕영주 2021. 3. 10. 12:50

Terraform provider OpenStack


refer to :

Install terraform


Download

root@yjwang0-stack-11:~/terraform# wget https://releases.hashicorp.com/terraform/0.14.7/terraform_0.14.7_linux_amd64.zip

Unzip

root@yjwang0-stack-11:~/terraform# unzip terraform_0.14.7_linux_amd64.zip 
Archive:  terraform_0.14.7_linux_amd64.zip
  inflating: terraform   

move to /usr/local/bin

root@yjwang0-stack-11:~/terraform# mv terraform /usr/local/bin/

confirm

root@yjwang0-stack-11:~/terraform# terraform --help
Usage: terraform [global options] <subcommand> [args]

The available commands for execution are listed below.
...

Test Openstack provider


Write .tf file

This file will create single instance

You can check your admin-openrc file for provider options

admin_pass를 지정했으나 ubuntu 2004에서는 반영되지 않았음.

root@yjwang0-stack-11:~/terraform# cat test.tf 
terraform {
required_version = ">= 0.14.0"
  required_providers {
    openstack = {
      source  = "terraform-provider-openstack/openstack"
      version = "~> 1.35.0"
    }
  }
}

provider "openstack" {
  user_name   = "admin"
  tenant_name = "admin"
  password    = "testtest"
  auth_url    = "http://10.99.99.190:35357/v3"
  region      = "RegionOne"
}

resource "openstack_compute_instance_v2" "test-instance" {
  name            = "test1-u2004"
  image_name      = "ubuntu-2004.qcow2"
  flavor_name     = "2-4096-20G"
  key_pair        = "host-root-key"
  security_groups = ["default"]
  admin_pass = "testtest"

  network {
    name = "provider"
  }
}

Run Scripts

root@yjwang0-stack-11:~/terraform# terraform init
root@yjwang0-stack-11:~/terraform# terraform plan
root@yjwang0-stack-11:~/terraform# terraform apply
...
Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes
...

Confirm

root@yjwang0-stack-11:~/terraform# openstack server list
+--------------------------------------+-------------+--------+-----------------------+--------------------------+------------+
| ID                                   | Name        | Status | Networks              | Image                    | Flavor     |
+--------------------------------------+-------------+--------+-----------------------+--------------------------+------------+
| 3c1c93b0-2ab3-4cb7-9e59-07f591b2ace1 | test1-u2004 | ACTIVE | provider=10.99.99.180 | ubuntu-2004.qcow2        | 2-4096-20G |

root@yjwang0-stack-11:~/terraform# ssh ubuntu@10.99.99.180

Delete Resources

root@yjwang0-stack-11:~/terraform# terraform destroy

Confirm

root@yjwang0-stack-11:~/terraform# openstack server list
반응형