RHEL8.4 ppc64leでオフラインで Terraformと terraform-provider-openstack を導入して仮想マシンをデプロイする

#### はじめに

Hashicorp社の Terraform ダウンロード・サイトに ppc64le 用のモジュールがないということを知り RHEL ppc64le でterraform が使えるのか、PowerVC でVMデプロイが動作するのかということを確認しました。


Hashicorp社の Terraform ダウンロード・サイト:  

https://developer.hashicorp.com/terraform/downloads?product_intent=terraform


---
#### 環境


RHEL 8.4 (ppc64le) on S824
　・ PowerVC 管理サーバーに Terraform を導入します。 
　　 PowerVC のバージョン は 2.0.2.1 です。

```
#  cat /etc/os-release | grep PRETTY
PRETTY_NAME="Red Hat Enterprise Linux 8.4 (Ootpa)"

# uname -a
Linux powervc-test 4.18.0-305.25.1.el8_4.ppc64le #1 SMP Mon Oct 18 14:27:13 EDT 2021 ppc64le ppc64le ppc64le GNU/Linux

# cat /opt/ibm/powervc/version.properties
[2.0.2.1 Install]
name = IBM PowerVC
version = 2.0.2.1
build = 20211203-0354
oem = no
install-date = 2021-12-29
cloud_enabled = yes
offering = private_cloud
cluster = powervc2021
```

---

#### 使用した Terraform rpm モジュール

サイト http://www.rpmfind.net で、ppc64le 版を見つけました。


・Terraform 0.13

http://www.rpmfind.net/linux/RPM/opensuse/15.5/ppc64le/terraform-0.13.4-6.3.1.ppc64le.html

・terraform openstack provider 

http://rpmfind.net/linux/RPM/opensuse/15.4/ppc64le/terraform-provider-openstack-1.43.0-bp154.1.33.ppc64le.html

---

#### Terraform, terraform-provider-openstack の導入


・terraform 0.13 を導入します

```
# rpm -ivh terraform-0.13.4-6.3.1.ppc64le.rpm
警告: terraform-0.13.4-6.3.1.ppc64le.rpm: ヘッダー V3 RSA/SHA256 Signature、鍵 ID 39db7c82: NOKEY
Verifying...                          ################################# [100%]
準備しています...              ################################# [100%]
更新中 / インストール中...
   1:terraform-0.13.4-6.3.1           ################################# [100%]
```

導入できました!

```
# which terraform
/usr/bin/terraform
```

---

#### terraform-provider-openstack 導入

```
# rpm -ivh terraform-provider-openstack-1.43.0-bp154.1.33.ppc64le.rpm
警告: terraform-provider-openstack-1.43.0-bp154.1.33.ppc64le.rpm: ヘッダー V3 RSA/SHA256 Signature、鍵 ID 65176565: NOKEY
Verifying...                          ################################# [100%]
準備しています...              ################################# [100%]
更新中 / インストール中...
   1:terraform-provider-openstack-1.43################################# [100%]
#
```


/usr/share/terraform/providers/ 下にプロバイダーが配置されました。


```
# ls -l /usr/share/terraform/providers/registry.terraform.io/hashicorp/openstack/1.43.0/linux_ppc64le
合計 0
lrwxrwxrwx. 1 root root 56  5月  9  2022 terraform-provider-openstack_v1.43.0 -> ../../../../../../../../bin/terraform-provider-openstack
```

---

#### 稼働確認

##### main.tf


VM作成の main.tf は以下を使用します。(xxx は環境固有値のためマスクしています)

```main.tf
provider "openstack" {
  user_name   = "root"
  password    = "xxxxx"
  tenant_name = "ibm-default"
  domain_name = "Default"
  auth_url    = "https://xx.xx.xx.xx:5000/v3/"   #<- PowerVC endpointを指定
  insecure    = true
}

resource "openstack_compute_instance_v2" "test" {
  name      = "testvm1"
  image_id  = "xxxxx-b60d-49b1-xxxx-6d0xxxxf2e"
  flavor_id = "c6xxxx89-e79c-xxxx-bc60-ba649xxxx00"

  network {
    uuid = "b5xxxxc4-9f05-4460-869f-a7xxxx6a62"
    name = "testnw1"
  }
}
```


---

##### terraform init の指定

terraform init でプラグイン・ディレクトリを指定することで、ローカルに導入したプラグインが使用されます。

- terraform init

```
# terraform init -plugin-dir=/usr/share/terraform/providers

Initializing the backend...

Initializing provider plugins...
- Finding latest version of hashicorp/openstack...
- Installing hashicorp/openstack v1.43.0...
- Installed hashicorp/openstack v1.43.0 (unauthenticated)

The following providers do not have any version constraints in configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain breaking
changes, we recommend adding version constraints in a required_providers block
in your configuration, with the constraint strings suggested below.

* hashicorp/openstack: version = "~> 1.43.0"

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
```


##### デプロイの実行

AIXをデプロイしています。


```
# terraform apply --auto-approve
openstack_compute_instance_v2.test: Creating...
openstack_compute_instance_v2.test: Still creating... [10s elapsed]
openstack_compute_instance_v2.test: Still creating... [20s elapsed]
openstack_compute_instance_v2.test: Still creating... [30s elapsed]
openstack_compute_instance_v2.test: Still creating... [40s elapsed]
openstack_compute_instance_v2.test: Still creating... [50s elapsed]
openstack_compute_instance_v2.test: Still creating... [1m0s elapsed]
openstack_compute_instance_v2.test: Still creating... [1m10s elapsed]
openstack_compute_instance_v2.test: Still creating... [1m20s elapsed]
openstack_compute_instance_v2.test: Still creating... [1m30s elapsed]
openstack_compute_instance_v2.test: Still creating... [1m40s elapsed]
openstack_compute_instance_v2.test: Still creating... [1m50s elapsed]
openstack_compute_instance_v2.test: Creation complete after 1m54s [id=4da03d2f-d6a1-414c-a612-dd74ae6f1b61]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
#
```


##### サーバー・デプロイ確認


```
# openstack server list | grep test0223
| 4xxx2f-d6a1-414c-a612-dd74xxxxb61 | test0223                     | ACTIVE  | VLAN1=192.168.xx.xx                       | AIX720503         | test0223                         |
```


```
# ping 192.168.xx.xx
PING 192.168.xx.xx (192.168.xx.xx) 56(84) bytes of data.
64 bytes from 192.168.xx.xx: icmp_seq=1 ttl=255 time=0.714 ms
^C
--- 192.168.xx.xx ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.714/0.714/0.714/0.000 ms
```
```
# ssh root@192.168.xx.xx
The authenticity of host '192.168.xx.xx (192.168.xx.xx)' can't be established.
RSA key fingerprint is SHA256:yHuNlsZxxxxxAw/4u16Jpkxxxxx6hrU.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.xx.xx' (RSA) to the list of known hosts.
root@192.168.xx.xx's password:
Last unsuccessful login: Sun Jan  9 11:05:38 JST 2022 on ssh from xx.xxx.xx.xxx
Last login: Tue Jan 11 08:21:19 JST 2022 on /dev/pts/0 from 192.168.xx.x
*******************************************************************************
*                                                                             *
*                                                                             *
*  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.                                  *
*                                                                             *
*                                                                             *
*******************************************************************************
[test0223:/]#
```

無事作成できています！



##### VM削除


```
# terraform destroy
openstack_compute_instance_v2.test: Refreshing state... [id=xxxxd2f-d6a1-414c-a612-dd74ae6f1b61]

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.test will be destroyed
  - resource "openstack_compute_instance_v2" "test" {
      - access_ip_v4        = "192.168.xx.xx" -> null
      - all_metadata        = {
          - "move_pin_vm"   = "false"
          - "original_host" = "828642A_xxxxx"
        } -> null
      - all_tags            = [] -> null
      - availability_zone   = "Default Group" -> null
      - flavor_id           = "c6xxxx89-e79c-xxxx-bc60-ba649xxxx00" -> null
      - flavor_name         = "test0223" -> null
      - force_delete        = false -> null
      - id                  = "4daxxxxf-d6a1-xxxx-a612-dd74axxxx61" -> null
      - image_id            = "xxxxx-b60d-49b1-xxxx-6d0xxxxf2e" -> null
      - image_name          = "AIX720503_default" -> null
      - name                = "test0223" -> null
      - power_state         = "active" -> null
      - region              = "RegionOne" -> null
      - security_groups     = [] -> null
      - stop_before_destroy = false -> null

      - network {
          - access_network = false -> null
          - fixed_ip_v4    = "192.168.xx.xx" -> null
          - mac            = "fa:xx:xx:d7:55:xx" -> null
          - name           = "testnw1" -> null
          - uuid           = "b5xxxxc4-xx05-xxxx-xx9f-a7xxxx6a62" -> null
        }
    }

Plan: 0 to add, 0 to change, 1 to destroy.

Do you really want to destroy all resources?
  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.test: Destroying... [id=4da03d2f-d6a1-414c-a612-dd74ae6f1b61]
openstack_compute_instance_v2.test: Still destroying... [id=xxxx3d2f-d6a1-414c-a612-dd74ae6f1b61, 10s elapsed]
openstack_compute_instance_v2.test: Still destroying... [id=xxxx3d2f-d6a1-414c-a612-dd74ae6f1b61, 20s elapsed]
openstack_compute_instance_v2.test: Still destroying... [id=xxxx3d2f-d6a1-414c-a612-dd74ae6f1b61, 30s elapsed]
openstack_compute_instance_v2.test: Still destroying... [id=xxxx03d2f-d6a1-414c-a612-dd74ae6f1b61, 40s elapsed]
openstack_compute_instance_v2.test: Destruction complete after 44s

Destroy complete! Resources: 1 destroyed.
#

```

---


Hashicorp社提供のモジュールではありませんが、rpmfind のモジュールを使用して、RHEL 8.4 ppc64le での Terraform、 terraform-provider-openstack の稼働が確認できました。


---
#### 追加情報

記事公開後に他サイトの情報を教えていただきました。

(1) Power で使用する ダウンロード可能なterraformの一覧
https://www.power-devops.com/terraform


(2) Deploying OpenShift on IBM Power Systems のサイトに ppc64le への terraform 、openstack-provider 導入方法

https://ocp-power-automation.github.io/ocp4-upi-kvm/docs/automation_host_prereqs/#terraform
https://ocp-power-automation.github.io/ocp4-upi-kvm/docs/automation_host_prereqs/#terraform-providers

(3) Terraform plugins for running ocp-power-automation on IBM Power systems Latest の archive.zip 内に terraform-provider-openstackが存在
https://github.com/ocp-power-automation/terraform-providers-power/releases

---
#### ご参考

Ansible を使用して PowerVC サーバーのローカルからデプロイする方法は下記をご参考ください。

https://qiita.com/c_u/items/95daed5b6171cc79321d


---



以上です。