NTNX>日記

個人的な趣味による Nutanix Community Edition 日記。Japanese のみですみません。

Nutanix CE / AHV に Terraform で VM 作成してみる。

Nutanix CE / AHV に、Terraform で VM を作成してみます。Terraform の Nutanix Provider を利用します。Nutanix CE は ce-2018.05.01-stable を利用しています。

www.terraform.io

Terrform の準備

今回の Terraform は、Oracle Linux 7 に RPM でインストールします。

[root@ol7-on-ahv ~]# cat /etc/oracle-release
Oracle Linux Server release 7.5
[root@ol7-on-ahv ~]# yum install -y --enablerepo=ol7_developer terraform

Terraform のバージョンです。

[root@ol7-on-ahv ~]# terraform -version
Terraform v0.11.11

今回の VM で利用する想定の、下記のリソースは作成してあります。それぞれ UUID を調べておきます。

  • イメージ サービス: OS のディスクイメージを登録ずみ。
  • ネットワーク: vlan-0 を作成ずみ。

ディスク イメージです。

CVM$ acli image.list | grep ol75-min-disk
ol75-min-disk                      kDiskImage  a73ebf41-ddc5-486b-977a-8e35bc70479f

Acropolis のネットワークです。

CVM$ acli net.list | grep vlan-0
vlan-0          47226b9d-85b5-46ee-ab05-90274a8554d2  kBridged  0

Terraform での VM 作成

Terraform の初期化(terraform init)を実行します。

[root@ol7-on-ahv tf]# terraform init

Initializing provider plugins...
- Checking for available provider plugins on https://releases.hashicorp.com...
- Downloading plugin for provider "nutanix" (1.0.0)...

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, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.

* provider.nutanix: version = "~> 1.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.
[root@ol7-on-ahv tf]#

tf ファイルは、下記のように作成しました。

gist.github.com

terraform apply を実行します。

[root@ol7-on-ahv tf]# terraform apply

実行の様子は、下記のようになります。

f:id:gowatana:20181224201527p:plain

途中で確認メッセージが表示されるので「yes」

f:id:gowatana:20181224201617p:plain

terraform apply が完了して、VM が作成されました。

f:id:gowatana:20181224201639p:plain

Prism で見ると、VM が作成され、起動しています。

f:id:gowatana:20181224201842p:plain

期待どおり、ディスク イメージとネットワークが割り当てられています。

f:id:gowatana:20181224201948p:plain

以上。

©2023 gowatana
クリエイティブ・コモンズ・ライセンスこの 作品 は クリエイティブ・コモンズ 表示 4.0 国際 ライセンスの下に提供されています。