Skip to content

Instantly share code, notes, and snippets.

@gowatana
Created December 19, 2021 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gowatana/f40fb52add48953d39928322f0198bd1 to your computer and use it in GitHub Desktop.
Save gowatana/f40fb52add48953d39928322f0198bd1 to your computer and use it in GitHub Desktop.
Nutanix AHV の Custom Script(Cloud-Init)で Terraform がインストールされた VM を作成する。(CentOS 8)
#cloud-config
disable_root: true
ssh_pwauth: true
package_upgrade: false
users:
- name: nutanix
lock-passwd: false
sudo: ALL=(ALL) NOPASSWD:ALL
chpasswd:
list: |
nutanix:nutanix/4u
expire: false
packages:
- git
- unzip
- epel-release
runcmd:
- dnf install -y jq
- mkdir -p /home/nutanix/bin
- curl -LO https://releases.hashicorp.com/terraform/1.1.2/terraform_1.1.2_linux_amd64.zip
- unzip terraform_1.1.2_linux_amd64.zip -d /home/nutanix/bin/
- echo 'complete -C /home/nutanix/bin/terraform terraform' >> /home/nutanix/.bashrc
- chown -R nutanix:nutanix /home/nutanix/bin
@gowatana
Copy link
Author

Terraform VM 作成自動化くん(CentOS 8)

Nutanix AHV の Custom Script(Cloud-Init)で Terraform がインストールされた VM を作成する。

事前準備

VM 作成例

  • CVM に SSH ログインして実行する。

VM を作成して、パワーオンする。

$ VMNAME=lab-vm-01
$ acli uhura.vm.create_with_customize $VMNAME num_vcpus=1 memory=2G cloudinit_userdata_path=https://gist.githubusercontent.com/gowatana/f40fb52add48953d39928322f0198bd1/raw/terraform-centos8-vm.yml
$ acli vm.disk_create $VMNAME clone_from_image=CentOS-8-GenericCloud-8.4.2105-20210603.0
$ acli vm.nic_create $VMNAME network=nw-vlan-11-ipam
$ acli vm.on $VMNAME

IP アドレスは AOS の IPAM による DHCP 自動設定なので、下記のコマンドか Prism などから確認する。

$ acli vm.nic_list $VMNAME

VM が起動したら下記で SSH ログインする。

  • ユーザ: nutanix
  • パスワード: nutanix/4u

Terraform が利用可能なはず。

$ terraform version
Terraform v1.1.2
on linux_amd64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment