IBM PowerVC Architect, Joe Cropper published an excellent article last year, in which he described how Terraform can be used with PowerVC, to deploy workloads in an Openstack environment. You can read it here:
https://developer.ibm.com/powervc/2017/06/29/infrastructure-code-terraform-meets-powervc/
I tested this in my lab recently. I downloaded Terraform to my Macbook and configured it to communicate with my PowerVC management server. Then I deployed a new AIX VM. It worked like a charm! I was impressed with how easy and quick it was to configure and use.
cgibson@xwing : ~/Downloads/TERRAFORM $ ./terraform -v
Terraform v0.11.7
+ provider.openstack v1.6.0
Following Joe’s instructions, I configured the main.tf file:
cgibson@xwing : ~/Downloads/TERRAFORM $ cat main.tf
provider "openstack" {
user_name = "pvcadmin"
password = "abc123"
tenant_name = "ibm-default"
domain_name = "Default"
auth_url = "https://pvc1:5000/v3/"
insecure = true
}
resource "openstack_compute_instance_v2" "TF-VM" {
name = "TF-VM"
image_id = "aaeb4f3c-7910-4365-96d7-0be5b45eb7fc"
flavor_id = "ee5e124b-03fc-4853-b6ad-a5cd34d75ffb"
network {
uuid = "1132cad9-8581-4f89-a25d-f7befcef5f32"
name = "VLAN55"
}
}
I deployed a new VM with “terraform apply”.
cgibson@xwing : ~/Downloads/TERRAFORM $ ./terraform apply
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
+ openstack_compute_instance_v2.TF-VM
id: <computed>
access_ip_v4: <computed>
access_ip_v6: <computed>
all_metadata.%: <computed>
availability_zone: <computed>
flavor_id: "ee5e124b-03fc-4853-b6ad-a5cd34d75ffb"
flavor_name: <computed>
force_delete: "false"
image_id: "aaeb4f3c-7910-4365-96d7-0be5b45eb7fc"
image_name: <computed>
name: "TF-VM"
network.#: "1"
network.0.access_network: "false"
network.0.fixed_ip_v4: <computed>
network.0.fixed_ip_v6: <computed>
network.0.floating_ip: <computed>
network.0.mac: <computed>
network.0.name: "VLAN55"
network.0.port: <computed>
network.0.uuid: "1132cad9-8581-4f89-a25d-f7befcef5f32"
region: <computed>
security_groups.#: <computed>
stop_before_destroy: "false"
Plan: 1 to add, 0 to change, 0 to destroy.
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
openstack_compute_instance_v2.TF-VM: Creating...
access_ip_v4: "" => "<computed>"
access_ip_v6: "" => "<computed>"
all_metadata.%: "" => "<computed>"
availability_zone: "" => "<computed>"
flavor_id: "" => "ee5e124b-03fc-4853-b6ad-a5cd34d75ffb"
flavor_name: "" => "<computed>"
force_delete: "" => "false"
image_id: "" => "aaeb4f3c-7910-4365-96d7-0be5b45eb7fc"
image_name: "" => "<computed>"
name: "" => "TF-VM"
network.#: "" => "1"
network.0.access_network: "" => "false"
network.0.fixed_ip_v4: "" => "<computed>"
network.0.fixed_ip_v6: "" => "<computed>"
network.0.floating_ip: "" => "<computed>"
network.0.mac: "" => "<computed>"
network.0.name: "" => "VLAN55"
network.0.port: "" => "<computed>"
network.0.uuid: "" => "1132cad9-8581-4f89-a25d-f7befcef5f32"
region: "" => "<computed>"
security_groups.#: "" => "<computed>"
stop_before_destroy: "" => "false"
openstack_compute_instance_v2.TF-VM: Still creating... (10s elapsed)
openstack_compute_instance_v2.TF-VM: Still creating... (20s elapsed)
openstack_compute_instance_v2.TF-VM: Still creating... (30s elapsed)
openstack_compute_instance_v2.TF-VM: Still creating... (40s elapsed)
openstack_compute_instance_v2.TF-VM: Still creating... (50s elapsed)
openstack_compute_instance_v2.TF-VM: Creation complete after 53s (ID: 123dcfeb-17ad-44aa-9907-affa0a12719b)
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
cgibson@xwing : ~/Downloads/TERRAFORM $ ls -ltr
total 198736
-rwxrwxr-x@ 1 cgibson staff 83486736 11 Apr 02:52 terraform
-rw-r--r--@ 1 cgibson staff 17754416 25 Jun 13:00 terraform_0.11.7_darwin_amd64.zip
-rw-r--r-- 1 cgibson staff 466 27 Jun 16:31 main.tf
-rw-r--r-- 1 cgibson staff 318 6 Jul 11:56 terraform.tfstate.backup
-rw-r--r-- 1 cgibson staff 2521 6 Jul 11:56 terraform.tfstate
cgibson@xwing : ~/Downloads/TERRAFORM $ cat terraform.tfstate
{
"version": 3,
"terraform_version": "0.11.7",
"serial": 10,
"lineage": "c58a694a-6a02-f766-0ae6-2ef696483a14",
"modules": [
{
"path": [
"root"
],
"outputs": {},
"resources": {
"openstack_compute_instance_v2.TF-VM": {
"type": "openstack_compute_instance_v2",
"depends_on": [],
"primary": {
"id": "123dcfeb-17ad-44aa-9907-affa0a12719b",
"attributes": {
"access_ip_v4": "10.2.55.108",
"access_ip_v6": "",
"all_metadata.%": "0",
"availability_zone": "nova",
"flavor_id": "ee5e124b-03fc-4853-b6ad-a5cd34d75ffb",
"flavor_name": "tiny",
"force_delete": "false",
"id": "123dcfeb-17ad-44aa-9907-affa0a12719b",
"image_id": "aaeb4f3c-7910-4365-96d7-0be5b45eb7fc",
"image_name": "AIX72CloudVM",
"name": "TF-VM",
"network.#": "1",
"network.0.access_network": "false",
"network.0.fixed_ip_v4": "10.2.55.108",
"network.0.fixed_ip_v6": "",
"network.0.floating_ip": "",
"network.0.mac": "fa:27:20:32:e0:20",
"network.0.name": "VLAN55",
"network.0.port": "",
"network.0.uuid": "1132cad9-8581-4f89-a25d-f7befcef5f32",
"region": "",
"security_groups.#": "0",
"stop_before_destroy": "false"
},
"meta": {
"e2bfb730-ecaa-11e6-8f88-34363bc7c4c0": {
"create": 1800000000000,
"delete": 1800000000000,
"update": 1800000000000
}
},
"tainted": false
},
"deposed": [],
"provider": "provider.openstack"
}
},
"depends_on": []
}
]
}
After a few minutes, I could ssh into the new VM, from my Macbook.
cgibson@xwing : ~/Downloads/TERRAFORM $ grep etwork.0.fixed_ip_v4 terraform.tfstate
"network.0.fixed_ip_v4": "10.2.55.108",
cgibson@xwing : ~/Downloads/TERRAFORM $ ping 10.2.55.108
PING 10.2.55.108 (10.2.55.108): 56 data bytes
64 bytes from 10.2.55.108: icmp_seq=0 ttl=253 time=27.739 ms
64 bytes from 10.2.55.108: icmp_seq=1 ttl=253 time=22.941 ms
64 bytes from 10.2.55.108: icmp_seq=2 ttl=253 time=23.213 ms
^C
--- 10.2.55.108 ping statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 22.941/24.631/27.739/2.200 ms
cgibson@xwing : ~/Downloads/TERRAFORM $
cgibson@xwing : ~/Downloads/TERRAFORM $ ssh root@10.2.55.108
root@10.2.55.108's password:
Last unsuccessful login: Thu Jul 5 20:27:26 CDT 2018 on ssh from 10.2.55.222
Last login: Thu Jul 5 20:27:29 CDT 2018 on /dev/pts/0 from 10.2.55.222
*******************************************************************************
* *
* *
* Welcome to AIX Version 7.2! *
* *
* *
* Please see the README file in /usr/lpp/bos for information pertinent to *
* this release of the AIX Operating System. *
* *
* *
*******************************************************************************
# oslevel -s
7200-02-02-1810
# lparstat -i
Node Name : tf-vm
Partition Name : TF-VM-123dcfeb-00000034
Partition Number : 5
Type : Shared-SMT-4
Mode : Uncapped
Entitled Capacity : 0.50
...
When I was done with the VM, I deleted it with “terraform destroy”.
cgibson@xwing : ~/Downloads/TERRAFORM $ ./terraform destroy
openstack_compute_instance_v2.TF-VM: Refreshing state... (ID: 123dcfeb-17ad-44aa-9907-affa0a12719b)
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
- destroy
Terraform will perform the following actions:
- openstack_compute_instance_v2.TF-VM
Plan: 0 to add, 0 to change, 1 to destroy.
Do you really want to destroy?
Terraform will destroy all your managed infrastructure, as shown above.
There is no undo. Only 'yes' will be accepted to confirm.
Enter a value: yes
openstack_compute_instance_v2.TF-VM: Destroying... (ID: 123dcfeb-17ad-44aa-9907-affa0a12719b)
openstack_compute_instance_v2.TF-VM: Still destroying... (ID: 123dcfeb-17ad-44aa-9907-affa0a12719b, 10s elapsed)
openstack_compute_instance_v2.TF-VM: Still destroying... (ID: 123dcfeb-17ad-44aa-9907-affa0a12719b, 20s elapsed)
openstack_compute_instance_v2.TF-VM: Destruction complete after 21s
Destroy complete! Resources: 1 destroyed.
On the PowerVC server, I saw corresponding messages appear in the log and observed the creation and deletion of the VM.
Creation of new VM
VM removal