LoginSignup
0
0

Wazi aaS: クラウド上でのメインフレーム開発環境構築 - (9) TerraformによるWazi aaS仮想サーバーの管理

Last updated at Posted at 2024-05-08

はじめに

IaC(Infrastracture as Code)の考え方に基づきクラウド上のリソースを管理するための機能を提供するTerraformというOSSがあります。
ここでは、Terraformを使用してWazi aaS仮想サーバーを管理する方法を試してみます。

TerraformによるIBM Cloudリソースの管理方法については以下の記事もご参照ください。
参考: TerraformによるIBM Cloudリソース管理

関連記事

Wazi aaS: クラウド上でのメインフレーム開発環境構築 - (1) 概要
Wazi aaS: クラウド上でのメインフレーム開発環境構築 - (2) 仮想サーバー作成
Wazi aaS: クラウド上でのメインフレーム開発環境構築 - (3) ネットワーク構成
Wazi aaS: クラウド上でのメインフレーム開発環境構築 - (4) Wazi aaS への接続
Wazi aaS: クラウド上でのメインフレーム開発環境構築 - (5) Stock Iamge確認
Wazi aaS: クラウド上でのメインフレーム開発環境構築 - (6) Stock Iamge基本操作/カスタマイズ
Wazi aaS: クラウド上でのメインフレーム開発環境構築 - (7) Wazi Image Builder
Wazi aaS: クラウド上でのメインフレーム開発環境構築 - (7)' Wazi Image Builder - Trouble Shootingメモ
Wazi aaS: クラウド上でのメインフレーム開発環境構築 - (8) Wazi aaS仮想サーバーの複製
Wazi aaS: クラウド上でのメインフレーム開発環境構築 - (9) TerraformによるWazi aaS仮想サーバーの管理

全体像

前の記事ではWazi aaS仮想サーバーをIBM Cloud上で複製する方法について記載しました。
それを応用して、ある1つのWazi aaS仮想サーバーをテンプレートと考え、それを元に必要に応じて仮想サーバーのインスタンスを動的に追加/削除する運用を考えてみます。まさにCloud環境の利点を活かして必要な時にインスタンスを作成し、不要になったら削除する、というような使い方のイメージです。そのような運用はTerraformを利用すると非常にスマートに行えます。

image.png

テンプレートとなる環境のスナップショットは事前に取得してある想定で、それを元に複製を作成する場合のTerraformによる管理方法を見ていきます。

TerraformによるWazi aaS仮想サーバー管理例

前提

テンプレート環境のスナップショットは取得済みの想定とします。
複製する仮想サーバーが配置されるリソース・グループ、VPC、サブネットは作成済みの想定とします。
IPアドレスはサブネット内で動的に割り当てられるものを使用する想定とします。
仮想サーバーに割り当てるセキュリティー・グループは作成済みの想定とします(共通のものを使用)。

環境情報

image.png

Windows11上のWSL(Ubuntu)にTerraformを導入し、そこからIBM Cloud上のWazi aaS仮想サーバーの管理を行えるようにします。

【使用するバージョン】
Ubuntu 20.04.6 LTS (Focal Fossa)
Terraform V1.7.5

構成ファイル

プロバイダー関連 / provider.tf

provider.tf
terraform {
  required_version = ">= 1.7"
  required_providers {
    ibm = {
      source = "IBM-Cloud/ibm"
      version = "~> 1.64.0"
    }
  }
}

# Configure the IBM Provider
provider "ibm" {
  ibmcloud_api_key = var.ibmcloud_api_key
  region = var.region
}

環境変数 / variables.tf

環境依存の情報は環境変数として与えられるようにしておきます。

variables.tf
variable "ibmcloud_api_key" {
  description = "Enter your IBM Cloud API Key, you can get your IBM Cloud API key using: https://cloud.ibm.com/iam#/apikeys"
}

# Target location for image
variable "region" {
  type        = string
  default     = "jp-tok"
  description = "Region for the VSI"
}

variable "zone" {
  type        = string
  default     = "2"
  description = "Zone for the VSI - data volumes will be stored here"
}

variable "target_resource_group_id" {
  type        = string
  default     = "Default"
  description = "Resource group id for target resources."
}

variable "target_vpc_name" {
  type        = string
  default     = "default"
}

variable "target_subnet_name" {
  type        = string
  default     = "default"
}

variable "secgrp_wazi_common_name" {
  type        = string
  default     = ""
}

# ssh private key to establish a session with data mover VSI
variable "ssh_private_key" {
  type        = string
  default     = "null"
}

# This is needed to be passed-in while creating the data mover VSI
variable "ssh_public_key" {
  type        = string
  default     = "null"
}

variable "wazi_template_bootvol_snapshotid" {
  type        = string
  default     = "null"
}

variable "wazi_template_datavol01_snapshotid" {
  type        = string
  default     = "null"
}

ローカル変数 / locals.tf

ここでWazi aaSインスタンスを制御するためのパラメーターを管理する想定です。

locals.tf
locals{
  waziaas_instance_profiles = {
    tagtest01 = {
        zone = "${var.region}-${var.zone}"
        vpc = data.ibm_is_vpc.target_vpc.id
        profile = "mz2-2x16"
        keys = [ibm_is_ssh_key.wazi_dummy.id]
        boot_volume_snapshot_id = var.wazi_template_bootvol_snapshotid
        subnet = data.ibm_is_subnet.target_subnet.id
        security_groups = [data.ibm_is_security_group.secgrp_wazi_common.id]
        datavol01_snapshot_id = var.wazi_template_datavol01_snapshotid
    }
  }
}

waziaas_instance_profilesというmap型の変数で、インスタンス毎のパラメーターを管理するようにしています。上の例ではまず"tagtest01"というインスタンスを1つだけ作成する想定で定義を作成しています。
インスタンスを増やす場合はここに"tagtest01"と同列にインスタンス情報を追加していく想定です。

リソース関連 / resources.tf

Terraformで管理する対象のリソース定義をしていきます。

resources.tf
# Existing VPC
data "ibm_is_vpc" "target_vpc" {
  name = var.target_vpc_name
} 

# Existing Subnet
data "ibm_is_subnet" "target_subnet" {
  name = var.target_subnet_name
  vpc  = data.ibm_is_vpc.target_vpc.id
}

# Existing Security Group
data "ibm_is_security_group" "secgrp_wazi_common" {
  name = var.secgrp_wazi_common_name
}

# create key pair
resource "tls_private_key" "ssh_key" {
  algorithm = "RSA"
}

# Write private key to local file for debugging
/*
resource "local_sensitive_file" "local_private_key" {
    content  = tls_private_key.ssh_key.private_key_openssh
    filename = "${path.module}/private_key"
}
*/

# register ssh key (This key is not actually used but it is required for creating a VSI)
resource "ibm_is_ssh_key" "wazi_dummy" {
  name      = "wazi-dummy"
  public_key = tls_private_key.ssh_key.public_key_openssh
  resource_group = var.target_resource_group_id
}

######################### WaziaaS Instances

# WaziaaS Instances
resource "ibm_is_instance" "waziaas_instances" {
  for_each = local.waziaas_instance_profiles

  name = each.key
  resource_group = var.target_resource_group_id
  zone = each.value.zone
  vpc = each.value.vpc
  profile = each.value.profile
  keys = each.value.keys
  boot_volume {
    name = "${each.key}-bootvol"
    snapshot = each.value.boot_volume_snapshot_id
  }
  primary_network_interface {
    subnet = each.value.subnet
    security_groups = each.value.security_groups
  }

}

# Datavol01 for WaziaaS Instances
resource "ibm_is_instance_volume_attachment" "waziaas_datavol01" {
  for_each = ibm_is_instance.waziaas_instances

  instance = each.value.id
  name = "${each.value.name}-datavol01"
  profile = "general-purpose"
  snapshot = lookup(local.waziaas_instance_profiles, each.value.name).datavol01_snapshot_id
  volume_name = "${each.value.name}-datavol01"
  delete_volume_on_attachment_delete = true
  delete_volume_on_instance_delete = true

} 

# Stop Wazi aaS instance for first time
resource "ibm_is_instance_action" "waziaas_action" {
  for_each = ibm_is_instance.waziaas_instances

  depends_on = [ibm_is_instance_volume_attachment.waziaas_datavol01]

  action       = "reboot"
  instance     = each.value.id
}

VPC、サブネット、セキュリティー・グループは既存のものを使用する想定で、dataブロックで定義しています。それぞれ使用するリソース名を変数で指定できるようにしています。

今回はテンプレート環境となるイメージのスナップショットを元にWazi aaSインスタンスを複製する想定です。なのでSSH keyの指定は実質意味がない(テンプレート環境のものが引き継がれる)のですが、VSI作成時にSSH Key指定は必須なので、ここではダミーのSSH keyを作成するようにしています。

【resource "ibm_is_instance"ブロック】
ここでWazi aaSインスタンスの定義を行っておりますが、for_eachを使用してローカル変数の"waziaas_instance_profiles"をベースにインスタンスを作成するように定義しています。
インスタンス毎に変更する可能性のあるパラメーターについては、waziaas_instance_profiles変数の中で指定した値が設定されるようにしています。

【resource "ibm_is_instance_volume_attachment"ブロック】
Wazi aaSインスタンスにアタッチするdata volumeの定義をしています。この例ではテンプレートとして使用する環境のdata volumeが1つのみという想定のため、1インスタンスにつき1つ定義を追加しています。

【resource "ibm_is_instance_action" ブロック】
Wazi aasインスタンス作成時には自動でインスタンス起動がされてしまうようですが、その後data volumeをアタッチしているのでうまく起動ができません。そのためdata volumeアタッチ後にrebootするようにこの定義を入れています。

環境変数への値設定 / my-settings.auto.vars

my-settings.auto.vars
ibmcloud_api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
region = "jp-tok"
zone = "2"
target_resource_group_id = "07c38a522f014e74aa065dfe2ab7f9af"
target_vpc_name = "vpc01"
target_subnet_name = "sn-20230715-02"
secgrp_wazi_common_name = "secgrp-wazi"
wazi_template_bootvol_snapshotid = "r022-b4e4ea78-b27c-44a4-88a3-ba670100a4ec"
wazi_template_datavol01_snapshotid = "r022-83ccc33d-4ac4-468a-8cc8-1d4198365802"

使用するリソース・グループ、VPC、サブネット、セキュリティー・グループ、テンプレートのスナップショットのID(boot用、data用)など、環境依存の情報はここで指定するようにしています。

Terraformオペレーション

それでは上の構成ファイルをIBM Cloud環境に適用してみます。

初期化 / terraform init

init
user01@IBM-PF3ALW3Q:~/Ansible/VSCode_workspace/my_terraform_wazi02$ terraform init

Initializing the backend...

Initializing provider plugins...
- Finding ibm-cloud/ibm versions matching "~> 1.64.0"...
- Finding latest version of hashicorp/tls...
- Installing ibm-cloud/ibm v1.64.1...
- Installed ibm-cloud/ibm v1.64.1 (self-signed, key ID AAD3B791C49CC253)
- Installing hashicorp/tls v4.0.5...
- Installed hashicorp/tls v4.0.5 (signed by HashiCorp)

Partner and community providers are signed by their developers.
If you'd like to know more about provider signing, you can read about it here:
https://www.terraform.io/docs/cli/plugins/signing.html

Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.

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.

事前確認 / terraform plan

plan
user01@IBM-PF3ALW3Q:~/Ansible/VSCode_workspace/my_terraform_wazi02$ terraform plan
data.ibm_is_vpc.target_vpc: Reading...
data.ibm_is_security_group.secgrp_wazi_common: Reading...
data.ibm_is_security_group.secgrp_wazi_common: Read complete after 6s [id=r022-f29b5e82-e744-4694-82db-8535e3eabafa]
data.ibm_is_vpc.target_vpc: Still reading... [10s elapsed]
data.ibm_is_vpc.target_vpc: Read complete after 11s [id=r022-a9e1fd5d-3911-4cd4-bfb0-032298831d34]
data.ibm_is_subnet.target_subnet: Reading...
data.ibm_is_subnet.target_subnet: Read complete after 1s [id=02f7-e9aecd6a-ed96-4f1d-9a14-1e3ca1863d74]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # ibm_is_instance.waziaas_instances["tagtest01"] will be created
  + resource "ibm_is_instance" "waziaas_instances" {
      + access_tags                       = (known after apply)
      + availability_policy_host_failure  = (known after apply)
      + bandwidth                         = (known after apply)
      + crn                               = (known after apply)
      + default_trusted_profile_auto_link = (known after apply)
      + disks                             = (known after apply)
      + force_action                      = false
      + gpu                               = (known after apply)
      + id                                = (known after apply)
      + image                             = (known after apply)
      + keys                              = (known after apply)
      + lifecycle_reasons                 = (known after apply)
      + lifecycle_state                   = (known after apply)
      + memory                            = (known after apply)
      + metadata_service_enabled          = (known after apply)
      + name                              = "tagtest01"
      + numa_count                        = (known after apply)
      + placement_target                  = (known after apply)
      + profile                           = "mz2-2x16"
      + reservation                       = (known after apply)
      + resource_controller_url           = (known after apply)
      + resource_crn                      = (known after apply)
      + resource_group                    = "07c38a522f014e74aa065dfe2ab7f9af"
      + resource_group_name               = (known after apply)
      + resource_name                     = (known after apply)
      + resource_status                   = (known after apply)
      + status                            = (known after apply)
      + status_reasons                    = (known after apply)
      + tags                              = (known after apply)
      + total_network_bandwidth           = (known after apply)
      + total_volume_bandwidth            = (known after apply)
      + vcpu                              = (known after apply)
      + volume_attachments                = (known after apply)
      + vpc                               = "r022-a9e1fd5d-3911-4cd4-bfb0-032298831d34"
      + wait_before_delete                = true
      + zone                              = "jp-tok-2"

      + boot_volume {
          + auto_delete_volume = true
          + encryption         = (known after apply)
          + iops               = (known after apply)
          + name               = "tagtest01-bootvol"
          + profile            = (known after apply)
          + size               = (known after apply)
          + snapshot           = "r022-b4e4ea78-b27c-44a4-88a3-ba670100a4ec"
          + tags               = (known after apply)
          + volume_id          = (known after apply)
        }

      + primary_network_interface {
          + allow_ip_spoofing    = false
          + id                   = (known after apply)
          + name                 = (known after apply)
          + port_speed           = (known after apply)
          + primary_ipv4_address = (known after apply)
          + security_groups      = [
              + "r022-f29b5e82-e744-4694-82db-8535e3eabafa",
            ]
          + subnet               = "02f7-e9aecd6a-ed96-4f1d-9a14-1e3ca1863d74"
        }
    }

  # ibm_is_instance_action.waziaas_action["tagtest01"] will be created
  + resource "ibm_is_instance_action" "waziaas_action" {
      + action         = "reboot"
      + force_action   = false
      + id             = (known after apply)
      + instance       = (known after apply)
      + status         = (known after apply)
      + status_reasons = (known after apply)
    }

  # ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest01"] will be created
  + resource "ibm_is_instance_volume_attachment" "waziaas_datavol01" {
      + capacity                           = (known after apply)
      + delete_volume_on_attachment_delete = true
      + delete_volume_on_instance_delete   = true
      + device                             = (known after apply)
      + encryption_key                     = (known after apply)
      + href                               = (known after apply)
      + id                                 = (known after apply)
      + instance                           = (known after apply)
      + iops                               = (known after apply)
      + name                               = "tagtest01-datavol01"
      + profile                            = "general-purpose"
      + snapshot                           = "r022-83ccc33d-4ac4-468a-8cc8-1d4198365802"
      + status                             = (known after apply)
      + tags                               = (known after apply)
      + type                               = (known after apply)
      + version                            = (known after apply)
      + volume                             = (known after apply)
      + volume_attachment_id               = (known after apply)
      + volume_crn                         = (known after apply)
      + volume_deleted                     = (known after apply)
      + volume_href                        = (known after apply)
      + volume_name                        = "tagtest01-datavol01"
    }

  # ibm_is_ssh_key.wazi_dummy will be created
  + resource "ibm_is_ssh_key" "wazi_dummy" {
      + access_tags             = (known after apply)
      + crn                     = (known after apply)
      + fingerprint             = (known after apply)
      + id                      = (known after apply)
      + length                  = (known after apply)
      + name                    = "wazi-dummy"
      + public_key              = (known after apply)
      + resource_controller_url = (known after apply)
      + resource_crn            = (known after apply)
      + resource_group          = "07c38a522f014e74aa065dfe2ab7f9af"
      + resource_group_name     = (known after apply)
      + resource_name           = (known after apply)
      + tags                    = (known after apply)
      + type                    = (known after apply)
    }

  # tls_private_key.ssh_key will be created
  + resource "tls_private_key" "ssh_key" {
      + algorithm                     = "RSA"
      + ecdsa_curve                   = "P224"
      + id                            = (known after apply)
      + private_key_openssh           = (sensitive value)
      + private_key_pem               = (sensitive value)
      + private_key_pem_pkcs8         = (sensitive value)
      + public_key_fingerprint_md5    = (known after apply)
      + public_key_fingerprint_sha256 = (known after apply)
      + public_key_openssh            = (known after apply)
      + public_key_pem                = (known after apply)
      + rsa_bits                      = 2048
    }

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

─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now.

適用 / terraform apply

apply
user01@IBM-PF3ALW3Q:~/Ansible/VSCode_workspace/my_terraform_wazi02$ terraform apply
data.ibm_is_security_group.secgrp_wazi_common: Reading...
data.ibm_is_vpc.target_vpc: Reading...
data.ibm_is_security_group.secgrp_wazi_common: Read complete after 8s [id=r022-f29b5e82-e744-4694-82db-8535e3eabafa]
data.ibm_is_vpc.target_vpc: Read complete after 9s [id=r022-a9e1fd5d-3911-4cd4-bfb0-032298831d34]
data.ibm_is_subnet.target_subnet: Reading...
data.ibm_is_subnet.target_subnet: Read complete after 4s [id=02f7-e9aecd6a-ed96-4f1d-9a14-1e3ca1863d74]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # ibm_is_instance.waziaas_instances["tagtest01"] will be created
  + resource "ibm_is_instance" "waziaas_instances" {
      + access_tags                       = (known after apply)
      + availability_policy_host_failure  = (known after apply)
      + bandwidth                         = (known after apply)
      + crn                               = (known after apply)
      + default_trusted_profile_auto_link = (known after apply)
      + disks                             = (known after apply)
      + force_action                      = false
      + gpu                               = (known after apply)
      + id                                = (known after apply)
      + image                             = (known after apply)
      + keys                              = (known after apply)
      + lifecycle_reasons                 = (known after apply)
      + lifecycle_state                   = (known after apply)
      + memory                            = (known after apply)
      + metadata_service_enabled          = (known after apply)
      + name                              = "tagtest01"
      + numa_count                        = (known after apply)
      + placement_target                  = (known after apply)
      + profile                           = "mz2-2x16"
      + reservation                       = (known after apply)
      + resource_controller_url           = (known after apply)
      + resource_crn                      = (known after apply)
      + resource_group                    = "07c38a522f014e74aa065dfe2ab7f9af"
      + resource_group_name               = (known after apply)
      + resource_name                     = (known after apply)
      + resource_status                   = (known after apply)
      + status                            = (known after apply)
      + status_reasons                    = (known after apply)
      + tags                              = (known after apply)
      + total_network_bandwidth           = (known after apply)
      + total_volume_bandwidth            = (known after apply)
      + vcpu                              = (known after apply)
      + volume_attachments                = (known after apply)
      + vpc                               = "r022-a9e1fd5d-3911-4cd4-bfb0-032298831d34"
      + wait_before_delete                = true
      + zone                              = "jp-tok-2"

      + boot_volume {
          + auto_delete_volume = true
          + encryption         = (known after apply)
          + iops               = (known after apply)
          + name               = "tagtest01-bootvol"
          + profile            = (known after apply)
          + size               = (known after apply)
          + snapshot           = "r022-b4e4ea78-b27c-44a4-88a3-ba670100a4ec"
          + tags               = (known after apply)
          + volume_id          = (known after apply)
        }

      + primary_network_interface {
          + allow_ip_spoofing    = false
          + id                   = (known after apply)
          + name                 = (known after apply)
          + port_speed           = (known after apply)
          + primary_ipv4_address = (known after apply)
          + security_groups      = [
              + "r022-f29b5e82-e744-4694-82db-8535e3eabafa",
            ]
          + subnet               = "02f7-e9aecd6a-ed96-4f1d-9a14-1e3ca1863d74"
        }
    }

  # ibm_is_instance_action.waziaas_action["tagtest01"] will be created
  + resource "ibm_is_instance_action" "waziaas_action" {
      + action         = "reboot"
      + force_action   = false
      + id             = (known after apply)
      + instance       = (known after apply)
      + status         = (known after apply)
      + status_reasons = (known after apply)
    }

  # ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest01"] will be created
  + resource "ibm_is_instance_volume_attachment" "waziaas_datavol01" {
      + capacity                           = (known after apply)
      + delete_volume_on_attachment_delete = true
      + delete_volume_on_instance_delete   = true
      + device                             = (known after apply)
      + encryption_key                     = (known after apply)
      + href                               = (known after apply)
      + id                                 = (known after apply)
      + instance                           = (known after apply)
      + iops                               = (known after apply)
      + name                               = "tagtest01-datavol01"
      + profile                            = "general-purpose"
      + snapshot                           = "r022-83ccc33d-4ac4-468a-8cc8-1d4198365802"
      + status                             = (known after apply)
      + tags                               = (known after apply)
      + type                               = (known after apply)
      + version                            = (known after apply)
      + volume                             = (known after apply)
      + volume_attachment_id               = (known after apply)
      + volume_crn                         = (known after apply)
      + volume_deleted                     = (known after apply)
      + volume_href                        = (known after apply)
      + volume_name                        = "tagtest01-datavol01"
    }

  # ibm_is_ssh_key.wazi_dummy will be created
  + resource "ibm_is_ssh_key" "wazi_dummy" {
      + access_tags             = (known after apply)
      + crn                     = (known after apply)
      + fingerprint             = (known after apply)
      + id                      = (known after apply)
      + length                  = (known after apply)
      + name                    = "wazi-dummy"
      + public_key              = (known after apply)
      + resource_controller_url = (known after apply)
      + resource_crn            = (known after apply)
      + resource_group          = "07c38a522f014e74aa065dfe2ab7f9af"
      + resource_group_name     = (known after apply)
      + resource_name           = (known after apply)
      + tags                    = (known after apply)
      + type                    = (known after apply)
    }

  # tls_private_key.ssh_key will be created
  + resource "tls_private_key" "ssh_key" {
      + algorithm                     = "RSA"
      + ecdsa_curve                   = "P224"
      + id                            = (known after apply)
      + private_key_openssh           = (sensitive value)
      + private_key_pem               = (sensitive value)
      + private_key_pem_pkcs8         = (sensitive value)
      + public_key_fingerprint_md5    = (known after apply)
      + public_key_fingerprint_sha256 = (known after apply)
      + public_key_openssh            = (known after apply)
      + public_key_pem                = (known after apply)
      + rsa_bits                      = 2048
    }

Plan: 5 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

tls_private_key.ssh_key: Creating...
tls_private_key.ssh_key: Creation complete after 0s [id=12faf55a2fa0473690080a6fbdf150751684dfbc]
ibm_is_ssh_key.wazi_dummy: Creating...
ibm_is_ssh_key.wazi_dummy: Creation complete after 9s [id=r022-ae873e5b-8fdc-4ca4-bcf0-f8ef6b14fa40]
ibm_is_instance.waziaas_instances["tagtest01"]: Creating...
ibm_is_instance.waziaas_instances["tagtest01"]: Still creating... [10s elapsed]
ibm_is_instance.waziaas_instances["tagtest01"]: Creation complete after 17s [id=02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f]
ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest01"]: Creating...
ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest01"]: Still creating... [10s elapsed]
ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest01"]: Creation complete after 11s [id=02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f/02f7-5057a25c-8848-44fa-bb50-db5a8ebff99a]
ibm_is_instance_action.waziaas_action["tagtest01"]: Creating...
ibm_is_instance_action.waziaas_action["tagtest01"]: Still creating... [10s elapsed]
ibm_is_instance_action.waziaas_action["tagtest01"]: Creation complete after 11s [id=02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f]

Apply complete! Resources: 5 added, 0 changed, 0 destroyed.

状況確認 / terraform state

state
user01@IBM-PF3ALW3Q:~/Ansible/VSCode_workspace/my_terraform_wazi02$ terraform state list
data.ibm_is_security_group.secgrp_wazi_common
data.ibm_is_subnet.target_subnet
data.ibm_is_vpc.target_vpc
ibm_is_instance.waziaas_instances["tagtest01"]
ibm_is_instance_action.waziaas_action["tagtest01"]
ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest01"]
ibm_is_ssh_key.wazi_dummy
tls_private_key.ssh_key

user01@IBM-PF3ALW3Q:~/Ansible/VSCode_workspace/my_terraform_wazi02$ terraform state show 'ibm_is_instance.waziaas_instances["tagtest01"]'
# ibm_is_instance.waziaas_instances["tagtest01"]:
resource "ibm_is_instance" "waziaas_instances" {
    access_tags                      = []
    availability_policy_host_failure = "restart"
    bandwidth                        = 4000
    crn                              = "crn:v1:bluemix:public:is:jp-tok-2:a/1fc8373f538a408187ffedbe62e5796a::instance:02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f"
    disks                            = []
    force_action                     = false
    gpu                              = []
    id                               = "02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f"
    image                            = "r022-7a175b16-59b2-476c-a246-da5e953fa722"
    keys                             = [
        "r022-ae873e5b-8fdc-4ca4-bcf0-f8ef6b14fa40",
    ]
    lifecycle_reasons                = []
    lifecycle_state                  = "stable"
    memory                           = 16
    metadata_service_enabled         = false
    name                             = "tagtest01"
    placement_target                 = []
    profile                          = "mz2-2x16"
    reservation                      = []
    resource_controller_url          = "https://cloud.ibm.com/vpc-ext/compute/vs"
    resource_crn                     = "crn:v1:bluemix:public:is:jp-tok-2:a/1fc8373f538a408187ffedbe62e5796a::instance:02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f"
    resource_group                   = "07c38a522f014e74aa065dfe2ab7f9af"
    resource_group_name              = "ISEI20230707-1626-nervous"
    resource_name                    = "tagtest01"
    resource_status                  = "running"
    status                           = "running"
    status_reasons                   = []
    tags                             = []
    total_network_bandwidth          = 3000
    total_volume_bandwidth           = 1000
    vcpu                             = [
        {
            architecture = "s390x"
            count        = 2
            manufacturer = "ibm"
        },
    ]
    volume_attachments               = [
        {
            id          = "02f7-183a1902-5f9d-4842-b748-931d2cbc89af"
            name        = "shoptalk-storewide-setup-gossip"
            volume_crn  = "crn:v1:bluemix:public:is:jp-tok-2:a/1fc8373f538a408187ffedbe62e5796a::volume:r022-3b2f3f3f-06fa-463f-ad55-e3ac6af801e9"
            volume_id   = "r022-3b2f3f3f-06fa-463f-ad55-e3ac6af801e9"
            volume_name = "tagtest01-bootvol"
        },
    ]
    vpc                              = "r022-a9e1fd5d-3911-4cd4-bfb0-032298831d34"
    wait_before_delete               = true
    zone                             = "jp-tok-2"

    boot_volume {
        auto_delete_volume = true
        iops               = 3000
        name               = "tagtest01-bootvol"
        profile            = "general-purpose"
        size               = 10
        snapshot           = "r022-b4e4ea78-b27c-44a4-88a3-ba670100a4ec"
        tags               = []
        volume_id          = "r022-3b2f3f3f-06fa-463f-ad55-e3ac6af801e9"
    }

    metadata_service {
        enabled            = false
        protocol           = "http"
        response_hop_limit = 1
    }

    primary_network_interface {
        allow_ip_spoofing    = false
        id                   = "02f7-c65731d7-cc48-4966-8a06-c3185a017693"
        name                 = "latterly-apricot-detract-foe"
        port_speed           = 3000
        primary_ipv4_address = "10.244.64.23"
        security_groups      = [
            "r022-f29b5e82-e744-4694-82db-8535e3eabafa",
        ]
        subnet               = "02f7-e9aecd6a-ed96-4f1d-9a14-1e3ca1863d74"

        primary_ip {
            address       = "10.244.64.23"
            auto_delete   = true
            href          = "https://jp-tok.iaas.cloud.ibm.com/v1/subnets/02f7-e9aecd6a-ed96-4f1d-9a14-1e3ca1863d74/reserved_ips/02f7-1e633a16-546c-4657-ae2f-e6c16dcc149d"
            name          = "unclog-map-snowless-repulsion"
            reserved_ip   = "02f7-1e633a16-546c-4657-ae2f-e6c16dcc149d"
            resource_type = "subnet_reserved_ip"
        }
    }

    reservation_affinity {
        policy = "disabled"
    }
}
IBM Cloud管理コンソールでの確認

image.png

image.png

構成ファイル変更(インスタンス追加)

locals.tf
locals{
  waziaas_instance_profiles = {
    tagtest01 = {
        zone = "${var.region}-${var.zone}"
        vpc = data.ibm_is_vpc.target_vpc.id
        profile = "mz2-2x16"
        keys = [ibm_is_ssh_key.wazi_dummy.id]
        boot_volume_snapshot_id = var.wazi_template_bootvol_snapshotid
        subnet = data.ibm_is_subnet.target_subnet.id
        security_groups = [data.ibm_is_security_group.secgrp_wazi_common.id]
        datavol01_snapshot_id = var.wazi_template_datavol01_snapshotid
    },
    tagtest02 = {
        zone = "${var.region}-${var.zone}"
        vpc = data.ibm_is_vpc.target_vpc.id
        profile = "mz2-2x16"
        keys = [ibm_is_ssh_key.wazi_dummy.id]
        boot_volume_snapshot_id = var.wazi_template_bootvol_snapshotid
        subnet = data.ibm_is_subnet.target_subnet.id
        security_groups = [data.ibm_is_security_group.secgrp_wazi_common.id]
        datavol01_snapshot_id = var.wazi_template_datavol01_snapshotid
    }
  }
}

locals.tf ファイルの waziaas_instance_profiles に もう一つインスタンス情報として"tagtest02"を追加してみます。

変更内容確認 / terraform plan

上の変更について事前確認します。

plan
user01@IBM-PF3ALW3Q:~/Ansible/VSCode_workspace/my_terraform_wazi02$ terraform plan
tls_private_key.ssh_key: Refreshing state... [id=12faf55a2fa0473690080a6fbdf150751684dfbc]
data.ibm_is_vpc.target_vpc: Reading...
data.ibm_is_security_group.secgrp_wazi_common: Reading...
ibm_is_ssh_key.wazi_dummy: Refreshing state... [id=r022-ae873e5b-8fdc-4ca4-bcf0-f8ef6b14fa40]
data.ibm_is_security_group.secgrp_wazi_common: Read complete after 6s [id=r022-f29b5e82-e744-4694-82db-8535e3eabafa]
data.ibm_is_vpc.target_vpc: Still reading... [10s elapsed]
data.ibm_is_vpc.target_vpc: Read complete after 10s [id=r022-a9e1fd5d-3911-4cd4-bfb0-032298831d34]
data.ibm_is_subnet.target_subnet: Reading...
data.ibm_is_subnet.target_subnet: Read complete after 1s [id=02f7-e9aecd6a-ed96-4f1d-9a14-1e3ca1863d74]
ibm_is_instance.waziaas_instances["tagtest01"]: Refreshing state... [id=02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f]
ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest01"]: Refreshing state... [id=02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f/02f7-5057a25c-8848-44fa-bb50-db5a8ebff99a]
ibm_is_instance_action.waziaas_action["tagtest01"]: Refreshing state... [id=02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # ibm_is_instance.waziaas_instances["tagtest02"] will be created
  + resource "ibm_is_instance" "waziaas_instances" {
      + access_tags                       = (known after apply)
      + availability_policy_host_failure  = (known after apply)
      + bandwidth                         = (known after apply)
      + crn                               = (known after apply)
      + default_trusted_profile_auto_link = (known after apply)
      + disks                             = (known after apply)
      + force_action                      = false
      + gpu                               = (known after apply)
      + id                                = (known after apply)
      + image                             = (known after apply)
      + keys                              = [
          + "r022-ae873e5b-8fdc-4ca4-bcf0-f8ef6b14fa40",
        ]
      + lifecycle_reasons                 = (known after apply)
      + lifecycle_state                   = (known after apply)
      + memory                            = (known after apply)
      + metadata_service_enabled          = (known after apply)
      + name                              = "tagtest02"
      + numa_count                        = (known after apply)
      + placement_target                  = (known after apply)
      + profile                           = "mz2-2x16"
      + reservation                       = (known after apply)
      + resource_controller_url           = (known after apply)
      + resource_crn                      = (known after apply)
      + resource_group                    = "07c38a522f014e74aa065dfe2ab7f9af"
      + resource_group_name               = (known after apply)
      + resource_name                     = (known after apply)
      + resource_status                   = (known after apply)
      + status                            = (known after apply)
      + status_reasons                    = (known after apply)
      + tags                              = (known after apply)
      + total_network_bandwidth           = (known after apply)
      + total_volume_bandwidth            = (known after apply)
      + vcpu                              = (known after apply)
      + volume_attachments                = (known after apply)
      + vpc                               = "r022-a9e1fd5d-3911-4cd4-bfb0-032298831d34"
      + wait_before_delete                = true
      + zone                              = "jp-tok-2"

      + boot_volume {
          + auto_delete_volume = true
          + encryption         = (known after apply)
          + iops               = (known after apply)
          + name               = "tagtest02-bootvol"
          + profile            = (known after apply)
          + size               = (known after apply)
          + snapshot           = "r022-b4e4ea78-b27c-44a4-88a3-ba670100a4ec"
          + tags               = (known after apply)
          + volume_id          = (known after apply)
        }

      + primary_network_interface {
          + allow_ip_spoofing    = false
          + id                   = (known after apply)
          + name                 = (known after apply)
          + port_speed           = (known after apply)
          + primary_ipv4_address = (known after apply)
          + security_groups      = [
              + "r022-f29b5e82-e744-4694-82db-8535e3eabafa",
            ]
          + subnet               = "02f7-e9aecd6a-ed96-4f1d-9a14-1e3ca1863d74"
        }
    }

  # ibm_is_instance_action.waziaas_action["tagtest02"] will be created
  + resource "ibm_is_instance_action" "waziaas_action" {
      + action         = "reboot"
      + force_action   = false
      + id             = (known after apply)
      + instance       = (known after apply)
      + status         = (known after apply)
      + status_reasons = (known after apply)
    }

  # ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest02"] will be created
  + resource "ibm_is_instance_volume_attachment" "waziaas_datavol01" {
      + capacity                           = (known after apply)
      + delete_volume_on_attachment_delete = true
      + delete_volume_on_instance_delete   = true
      + device                             = (known after apply)
      + encryption_key                     = (known after apply)
      + href                               = (known after apply)
      + id                                 = (known after apply)
      + instance                           = (known after apply)
      + iops                               = (known after apply)
      + name                               = "tagtest02-datavol01"
      + profile                            = "general-purpose"
      + snapshot                           = "r022-83ccc33d-4ac4-468a-8cc8-1d4198365802"
      + status                             = (known after apply)
      + tags                               = (known after apply)
      + type                               = (known after apply)
      + version                            = (known after apply)
      + volume                             = (known after apply)
      + volume_attachment_id               = (known after apply)
      + volume_crn                         = (known after apply)
      + volume_deleted                     = (known after apply)
      + volume_href                        = (known after apply)
      + volume_name                        = "tagtest02-datavol01"
    }

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

─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now.

Wazi aaSインスタンス、data volumeアタッチ、action(リブート用)の3つのリソースが追加で作成される予定であることが確認できました。

変更の適用 / terraform apply

実際に変更を適用します。

apply
user01@IBM-PF3ALW3Q:~/Ansible/VSCode_workspace/my_terraform_wazi02$ terraform apply
tls_private_key.ssh_key: Refreshing state... [id=12faf55a2fa0473690080a6fbdf150751684dfbc]
data.ibm_is_security_group.secgrp_wazi_common: Reading...
data.ibm_is_vpc.target_vpc: Reading...
ibm_is_ssh_key.wazi_dummy: Refreshing state... [id=r022-ae873e5b-8fdc-4ca4-bcf0-f8ef6b14fa40]
data.ibm_is_security_group.secgrp_wazi_common: Read complete after 6s [id=r022-f29b5e82-e744-4694-82db-8535e3eabafa]
data.ibm_is_vpc.target_vpc: Still reading... [10s elapsed]
data.ibm_is_vpc.target_vpc: Read complete after 11s [id=r022-a9e1fd5d-3911-4cd4-bfb0-032298831d34]
data.ibm_is_subnet.target_subnet: Reading...
data.ibm_is_subnet.target_subnet: Read complete after 0s [id=02f7-e9aecd6a-ed96-4f1d-9a14-1e3ca1863d74]
ibm_is_instance.waziaas_instances["tagtest01"]: Refreshing state... [id=02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f]
ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest01"]: Refreshing state... [id=02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f/02f7-5057a25c-8848-44fa-bb50-db5a8ebff99a]
ibm_is_instance_action.waziaas_action["tagtest01"]: Refreshing state... [id=02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # ibm_is_instance.waziaas_instances["tagtest02"] will be created
  + resource "ibm_is_instance" "waziaas_instances" {
      + access_tags                       = (known after apply)
      + availability_policy_host_failure  = (known after apply)
      + bandwidth                         = (known after apply)
      + crn                               = (known after apply)
      + default_trusted_profile_auto_link = (known after apply)
      + disks                             = (known after apply)
      + force_action                      = false
      + gpu                               = (known after apply)
      + id                                = (known after apply)
      + image                             = (known after apply)
      + keys                              = [
          + "r022-ae873e5b-8fdc-4ca4-bcf0-f8ef6b14fa40",
        ]
      + lifecycle_reasons                 = (known after apply)
      + lifecycle_state                   = (known after apply)
      + memory                            = (known after apply)
      + metadata_service_enabled          = (known after apply)
      + name                              = "tagtest02"
      + numa_count                        = (known after apply)
      + placement_target                  = (known after apply)
      + profile                           = "mz2-2x16"
      + reservation                       = (known after apply)
      + resource_controller_url           = (known after apply)
      + resource_crn                      = (known after apply)
      + resource_group                    = "07c38a522f014e74aa065dfe2ab7f9af"
      + resource_group_name               = (known after apply)
      + resource_name                     = (known after apply)
      + resource_status                   = (known after apply)
      + status                            = (known after apply)
      + status_reasons                    = (known after apply)
      + tags                              = (known after apply)
      + total_network_bandwidth           = (known after apply)
      + total_volume_bandwidth            = (known after apply)
      + vcpu                              = (known after apply)
      + volume_attachments                = (known after apply)
      + vpc                               = "r022-a9e1fd5d-3911-4cd4-bfb0-032298831d34"
      + wait_before_delete                = true
      + zone                              = "jp-tok-2"

      + boot_volume {
          + auto_delete_volume = true
          + encryption         = (known after apply)
          + iops               = (known after apply)
          + name               = "tagtest02-bootvol"
          + profile            = (known after apply)
          + size               = (known after apply)
          + snapshot           = "r022-b4e4ea78-b27c-44a4-88a3-ba670100a4ec"
          + tags               = (known after apply)
          + volume_id          = (known after apply)
        }

      + primary_network_interface {
          + allow_ip_spoofing    = false
          + id                   = (known after apply)
          + name                 = (known after apply)
          + port_speed           = (known after apply)
          + primary_ipv4_address = (known after apply)
          + security_groups      = [
              + "r022-f29b5e82-e744-4694-82db-8535e3eabafa",
            ]
          + subnet               = "02f7-e9aecd6a-ed96-4f1d-9a14-1e3ca1863d74"
        }
    }

  # ibm_is_instance_action.waziaas_action["tagtest02"] will be created
  + resource "ibm_is_instance_action" "waziaas_action" {
      + action         = "reboot"
      + force_action   = false
      + id             = (known after apply)
      + instance       = (known after apply)
      + status         = (known after apply)
      + status_reasons = (known after apply)
    }

  # ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest02"] will be created
  + resource "ibm_is_instance_volume_attachment" "waziaas_datavol01" {
      + capacity                           = (known after apply)
      + delete_volume_on_attachment_delete = true
      + delete_volume_on_instance_delete   = true
      + device                             = (known after apply)
      + encryption_key                     = (known after apply)
      + href                               = (known after apply)
      + id                                 = (known after apply)
      + instance                           = (known after apply)
      + iops                               = (known after apply)
      + name                               = "tagtest02-datavol01"
      + profile                            = "general-purpose"
      + snapshot                           = "r022-83ccc33d-4ac4-468a-8cc8-1d4198365802"
      + status                             = (known after apply)
      + tags                               = (known after apply)
      + type                               = (known after apply)
      + version                            = (known after apply)
      + volume                             = (known after apply)
      + volume_attachment_id               = (known after apply)
      + volume_crn                         = (known after apply)
      + volume_deleted                     = (known after apply)
      + volume_href                        = (known after apply)
      + volume_name                        = "tagtest02-datavol01"
    }

Plan: 3 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

ibm_is_instance.waziaas_instances["tagtest02"]: Creating...
ibm_is_instance.waziaas_instances["tagtest02"]: Still creating... [10s elapsed]
ibm_is_instance.waziaas_instances["tagtest02"]: Still creating... [20s elapsed]
ibm_is_instance.waziaas_instances["tagtest02"]: Creation complete after 24s [id=02f7_472210fd-f6c4-4cea-9d17-a77ce422eb9a]
ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest02"]: Creating...
ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest02"]: Still creating... [10s elapsed]
ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest02"]: Creation complete after 12s [id=02f7_472210fd-f6c4-4cea-9d17-a77ce422eb9a/02f7-9788f656-ec80-4226-98a1-b40a170a1024]
ibm_is_instance_action.waziaas_action["tagtest02"]: Creating...
ibm_is_instance_action.waziaas_action["tagtest02"]: Still creating... [10s elapsed]
ibm_is_instance_action.waziaas_action["tagtest02"]: Creation complete after 11s [id=02f7_472210fd-f6c4-4cea-9d17-a77ce422eb9a]

Apply complete! Resources: 3 added, 0 changed, 0 destroyed.

状況確認 / terraform state

state
user01@IBM-PF3ALW3Q:~/Ansible/VSCode_workspace/my_terraform_wazi02$ terraform state list
data.ibm_is_security_group.secgrp_wazi_common
data.ibm_is_subnet.target_subnet
data.ibm_is_vpc.target_vpc
ibm_is_instance.waziaas_instances["tagtest01"]
ibm_is_instance.waziaas_instances["tagtest02"]
ibm_is_instance_action.waziaas_action["tagtest01"]
ibm_is_instance_action.waziaas_action["tagtest02"]
ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest01"]
ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest02"]
ibm_is_ssh_key.wazi_dummy
tls_private_key.ssh_key

user01@IBM-PF3ALW3Q:~/Ansible/VSCode_workspace/my_terraform_wazi02$ terraform state show 'ibm_is_instance.waziaas_instances["tagtest02"]'
# ibm_is_instance.waziaas_instances["tagtest02"]:
resource "ibm_is_instance" "waziaas_instances" {
    access_tags                      = []
    availability_policy_host_failure = "restart"
    bandwidth                        = 4000
    crn                              = "crn:v1:bluemix:public:is:jp-tok-2:a/1fc8373f538a408187ffedbe62e5796a::instance:02f7_472210fd-f6c4-4cea-9d17-a77ce422eb9a"
    disks                            = []
    force_action                     = false
    gpu                              = []
    id                               = "02f7_472210fd-f6c4-4cea-9d17-a77ce422eb9a"
    image                            = "r022-7a175b16-59b2-476c-a246-da5e953fa722"
    keys                             = [
        "r022-ae873e5b-8fdc-4ca4-bcf0-f8ef6b14fa40",
    ]
    lifecycle_reasons                = []
    lifecycle_state                  = "stable"
    memory                           = 16
    metadata_service_enabled         = false
    name                             = "tagtest02"
    placement_target                 = []
    profile                          = "mz2-2x16"
    reservation                      = []
    resource_controller_url          = "https://cloud.ibm.com/vpc-ext/compute/vs"
    resource_crn                     = "crn:v1:bluemix:public:is:jp-tok-2:a/1fc8373f538a408187ffedbe62e5796a::instance:02f7_472210fd-f6c4-4cea-9d17-a77ce422eb9a"
    resource_group                   = "07c38a522f014e74aa065dfe2ab7f9af"
    resource_group_name              = "ISEI20230707-1626-nervous"
    resource_name                    = "tagtest02"
    resource_status                  = "running"
    status                           = "running"
    status_reasons                   = []
    tags                             = []
    total_network_bandwidth          = 3000
    total_volume_bandwidth           = 1000
    vcpu                             = [
        {
            architecture = "s390x"
            count        = 2
            manufacturer = "ibm"
        },
    ]
    volume_attachments               = [
        {
            id          = "02f7-ef9c134e-6fc2-46e6-a579-f5cbb34dbc90"
            name        = "autoalarm-tropics-wrung-divinely"
            volume_crn  = "crn:v1:bluemix:public:is:jp-tok-2:a/1fc8373f538a408187ffedbe62e5796a::volume:r022-2ea309a0-7d56-4e1b-b677-4ef5e7887236"
            volume_id   = "r022-2ea309a0-7d56-4e1b-b677-4ef5e7887236"
            volume_name = "tagtest02-bootvol"
        },
    ]
    vpc                              = "r022-a9e1fd5d-3911-4cd4-bfb0-032298831d34"
    wait_before_delete               = true
    zone                             = "jp-tok-2"

    boot_volume {
        auto_delete_volume = true
        iops               = 3000
        name               = "tagtest02-bootvol"
        profile            = "general-purpose"
        size               = 10
        snapshot           = "r022-b4e4ea78-b27c-44a4-88a3-ba670100a4ec"
        tags               = []
        volume_id          = "r022-2ea309a0-7d56-4e1b-b677-4ef5e7887236"
    }

    metadata_service {
        enabled            = false
        protocol           = "http"
        response_hop_limit = 1
    }

    primary_network_interface {
        allow_ip_spoofing    = false
        id                   = "02f7-464b9390-1123-48f0-a83e-82fd58ae3741"
        name                 = "calf-revenge-shut-reprise"
        port_speed           = 3000
        primary_ipv4_address = "10.244.64.25"
        security_groups      = [
            "r022-f29b5e82-e744-4694-82db-8535e3eabafa",
        ]
        subnet               = "02f7-e9aecd6a-ed96-4f1d-9a14-1e3ca1863d74"

        primary_ip {
            address       = "10.244.64.25"
            auto_delete   = true
            href          = "https://jp-tok.iaas.cloud.ibm.com/v1/subnets/02f7-e9aecd6a-ed96-4f1d-9a14-1e3ca1863d74/reserved_ips/02f7-9b015fa8-0e4a-49b6-a74f-e915bf67d71d"
            name          = "sincere-palpable-ducktail-kithe"
            reserved_ip   = "02f7-9b015fa8-0e4a-49b6-a74f-e915bf67d71d"
            resource_type = "subnet_reserved_ip"
        }
    }

    reservation_affinity {
        policy = "disabled"
    }
}
IBM Cloud管理コンソールでの確認

image.png

image.png

image.png

構成ファイル変更(インスタンス削除)

インスタンスを1つ削除してみます。

locals.tf
locals{
  waziaas_instance_profiles = {
    tagtest02 = {
        zone = "${var.region}-${var.zone}"
        vpc = data.ibm_is_vpc.target_vpc.id
        profile = "mz2-2x16"
        keys = [ibm_is_ssh_key.wazi_dummy.id]
        boot_volume_snapshot_id = var.wazi_template_bootvol_snapshotid
        subnet = data.ibm_is_subnet.target_subnet.id
        security_groups = [data.ibm_is_security_group.secgrp_wazi_common.id]
        datavol01_snapshot_id = var.wazi_template_datavol01_snapshotid
    }
  }
}

ここでは、最初に定義していたtagtest01の情報をwaziaas_instance_profilesから削除し、tagtest02を残すようにしてみます。

変更内容確認 / terraform plan

plan
user01@IBM-PF3ALW3Q:~/Ansible/VSCode_workspace/my_terraform_wazi02$ terraform plan
tls_private_key.ssh_key: Refreshing state... [id=12faf55a2fa0473690080a6fbdf150751684dfbc]
data.ibm_is_vpc.target_vpc: Reading...
data.ibm_is_security_group.secgrp_wazi_common: Reading...
ibm_is_ssh_key.wazi_dummy: Refreshing state... [id=r022-ae873e5b-8fdc-4ca4-bcf0-f8ef6b14fa40]
data.ibm_is_security_group.secgrp_wazi_common: Read complete after 7s [id=r022-f29b5e82-e744-4694-82db-8535e3eabafa]
data.ibm_is_vpc.target_vpc: Read complete after 8s [id=r022-a9e1fd5d-3911-4cd4-bfb0-032298831d34]
data.ibm_is_subnet.target_subnet: Reading...
data.ibm_is_subnet.target_subnet: Read complete after 1s [id=02f7-e9aecd6a-ed96-4f1d-9a14-1e3ca1863d74]
ibm_is_instance.waziaas_instances["tagtest01"]: Refreshing state... [id=02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f]
ibm_is_instance.waziaas_instances["tagtest02"]: Refreshing state... [id=02f7_472210fd-f6c4-4cea-9d17-a77ce422eb9a]
ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest01"]: Refreshing state... [id=02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f/02f7-5057a25c-8848-44fa-bb50-db5a8ebff99a]
ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest02"]: Refreshing state... [id=02f7_472210fd-f6c4-4cea-9d17-a77ce422eb9a/02f7-9788f656-ec80-4226-98a1-b40a170a1024]
ibm_is_instance_action.waziaas_action["tagtest02"]: Refreshing state... [id=02f7_472210fd-f6c4-4cea-9d17-a77ce422eb9a]
ibm_is_instance_action.waziaas_action["tagtest01"]: Refreshing state... [id=02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  - destroy

Terraform will perform the following actions:

  # ibm_is_instance.waziaas_instances["tagtest01"] will be destroyed
  # (because key ["tagtest01"] is not in for_each map)
  - resource "ibm_is_instance" "waziaas_instances" {
      - access_tags                      = [] -> null
      - availability_policy_host_failure = "restart" -> null
      - bandwidth                        = 4000 -> null
      - crn                              = "crn:v1:bluemix:public:is:jp-tok-2:a/1fc8373f538a408187ffedbe62e5796a::instance:02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f" -> null
      - disks                            = [] -> null
      - force_action                     = false -> null
      - gpu                              = [] -> null
      - id                               = "02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f" -> null
      - image                            = "r022-7a175b16-59b2-476c-a246-da5e953fa722" -> null
      - keys                             = [
          - "r022-ae873e5b-8fdc-4ca4-bcf0-f8ef6b14fa40",
        ] -> null
      - lifecycle_reasons                = [] -> null
      - lifecycle_state                  = "stable" -> null
      - memory                           = 16 -> null
      - metadata_service_enabled         = false -> null
      - name                             = "tagtest01" -> null
      - placement_target                 = [] -> null
      - profile                          = "mz2-2x16" -> null
      - reservation                      = [] -> null
      - resource_controller_url          = "https://cloud.ibm.com/vpc-ext/compute/vs" -> null
      - resource_crn                     = "crn:v1:bluemix:public:is:jp-tok-2:a/1fc8373f538a408187ffedbe62e5796a::instance:02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f" -> null
      - resource_group                   = "07c38a522f014e74aa065dfe2ab7f9af" -> null
      - resource_group_name              = "ISEI20230707-1626-nervous" -> null
      - resource_name                    = "tagtest01" -> null
      - resource_status                  = "running" -> null
      - status                           = "running" -> null
      - status_reasons                   = [] -> null
      - tags                             = [] -> null
      - total_network_bandwidth          = 3000 -> null
      - total_volume_bandwidth           = 1000 -> null
      - vcpu                             = [
          - {
              - architecture = "s390x"
              - count        = 2
              - manufacturer = "ibm"
            },
        ] -> null
      - volume_attachments               = [
          - {
              - id          = "02f7-183a1902-5f9d-4842-b748-931d2cbc89af"
              - name        = "shoptalk-storewide-setup-gossip"
              - volume_crn  = "crn:v1:bluemix:public:is:jp-tok-2:a/1fc8373f538a408187ffedbe62e5796a::volume:r022-3b2f3f3f-06fa-463f-ad55-e3ac6af801e9"
              - volume_id   = "r022-3b2f3f3f-06fa-463f-ad55-e3ac6af801e9"
              - volume_name = "tagtest01-bootvol"
            },
          - {
              - id          = "02f7-5057a25c-8848-44fa-bb50-db5a8ebff99a"
              - name        = "tagtest01-datavol01"
              - volume_crn  = "crn:v1:bluemix:public:is:jp-tok-2:a/1fc8373f538a408187ffedbe62e5796a::volume:r022-5ccc3dc7-3ec9-4e57-854b-116010f671ae"
              - volume_id   = "r022-5ccc3dc7-3ec9-4e57-854b-116010f671ae"
              - volume_name = "tagtest01-datavol01"
            },
        ] -> null
      - vpc                              = "r022-a9e1fd5d-3911-4cd4-bfb0-032298831d34" -> null
      - wait_before_delete               = true -> null
      - zone                             = "jp-tok-2" -> null

      - boot_volume {
          - auto_delete_volume = true -> null
          - iops               = 3000 -> null
          - name               = "tagtest01-bootvol" -> null
          - profile            = "general-purpose" -> null
          - size               = 10 -> null
          - snapshot           = "r022-b4e4ea78-b27c-44a4-88a3-ba670100a4ec" -> null
          - tags               = [] -> null
          - volume_id          = "r022-3b2f3f3f-06fa-463f-ad55-e3ac6af801e9" -> null
        }

      - metadata_service {
          - enabled            = false -> null
          - protocol           = "http" -> null
          - response_hop_limit = 1 -> null
        }

      - primary_network_interface {
          - allow_ip_spoofing    = false -> null
          - id                   = "02f7-c65731d7-cc48-4966-8a06-c3185a017693" -> null
          - name                 = "latterly-apricot-detract-foe" -> null
          - port_speed           = 3000 -> null
          - primary_ipv4_address = "10.244.64.23" -> null
          - security_groups      = [
              - "r022-f29b5e82-e744-4694-82db-8535e3eabafa",
            ] -> null
          - subnet               = "02f7-e9aecd6a-ed96-4f1d-9a14-1e3ca1863d74" -> null

          - primary_ip {
              - address       = "10.244.64.23" -> null
              - auto_delete   = true -> null
              - href          = "https://jp-tok.iaas.cloud.ibm.com/v1/subnets/02f7-e9aecd6a-ed96-4f1d-9a14-1e3ca1863d74/reserved_ips/02f7-1e633a16-546c-4657-ae2f-e6c16dcc149d" -> null
              - name          = "unclog-map-snowless-repulsion" -> null
              - reserved_ip   = "02f7-1e633a16-546c-4657-ae2f-e6c16dcc149d" -> null
              - resource_type = "subnet_reserved_ip" -> null
            }
        }

      - reservation_affinity {
          - policy = "disabled" -> null
        }
    }

  # ibm_is_instance_action.waziaas_action["tagtest01"] will be destroyed
  # (because key ["tagtest01"] is not in for_each map)
  - resource "ibm_is_instance_action" "waziaas_action" {
      - action         = "reboot" -> null
      - force_action   = false -> null
      - id             = "02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f" -> null
      - instance       = "02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f" -> null
      - status         = "running" -> null
      - status_reasons = [] -> null
    }

  # ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest01"] will be destroyed
  # (because key ["tagtest01"] is not in for_each map)
  - resource "ibm_is_instance_volume_attachment" "waziaas_datavol01" {
      - capacity                           = 66 -> null
      - delete_volume_on_attachment_delete = true -> null
      - delete_volume_on_instance_delete   = true -> null
      - device                             = "02f7-5057a25c-8848-44fa-bb50-db5a8ebff99a-7gfv5" -> null
      - href                               = "https://jp-tok.iaas.cloud.ibm.com/v1/instances/02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f/volume_attachments/02f7-5057a25c-8848-44fa-bb50-db5a8ebff99a" -> null
      - id                                 = "02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f/02f7-5057a25c-8848-44fa-bb50-db5a8ebff99a" -> null
      - instance                           = "02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f" -> null
      - iops                               = 3000 -> null
      - name                               = "tagtest01-datavol01" -> null
      - profile                            = "general-purpose" -> null
      - snapshot                           = "r022-83ccc33d-4ac4-468a-8cc8-1d4198365802" -> null
      - status                             = "attached" -> null
      - tags                               = [] -> null
      - type                               = "data" -> null
      - volume                             = "r022-5ccc3dc7-3ec9-4e57-854b-116010f671ae" -> null
      - volume_attachment_id               = "02f7-5057a25c-8848-44fa-bb50-db5a8ebff99a" -> null
      - volume_crn                         = "crn:v1:bluemix:public:is:jp-tok-2:a/1fc8373f538a408187ffedbe62e5796a::volume:r022-5ccc3dc7-3ec9-4e57-854b-116010f671ae" -> null
      - volume_href                        = "https://jp-tok.iaas.cloud.ibm.com/v1/volumes/r022-5ccc3dc7-3ec9-4e57-854b-116010f671ae" -> null
      - volume_name                        = "tagtest01-datavol01" -> null
    }

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

─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now.

Wazi aaSインスタンス"tagtest01"とそれに関連するdata volumeアタッチ、action用のリソースが削除される予定であることが確認できました。

変更の適用 / terraform apply

apply
user01@IBM-PF3ALW3Q:~/Ansible/VSCode_workspace/my_terraform_wazi02$ terraform apply
tls_private_key.ssh_key: Refreshing state... [id=12faf55a2fa0473690080a6fbdf150751684dfbc]
data.ibm_is_vpc.target_vpc: Reading...
data.ibm_is_security_group.secgrp_wazi_common: Reading...
ibm_is_ssh_key.wazi_dummy: Refreshing state... [id=r022-ae873e5b-8fdc-4ca4-bcf0-f8ef6b14fa40]
data.ibm_is_security_group.secgrp_wazi_common: Read complete after 6s [id=r022-f29b5e82-e744-4694-82db-8535e3eabafa]
data.ibm_is_vpc.target_vpc: Read complete after 7s [id=r022-a9e1fd5d-3911-4cd4-bfb0-032298831d34]
data.ibm_is_subnet.target_subnet: Reading...
data.ibm_is_subnet.target_subnet: Read complete after 1s [id=02f7-e9aecd6a-ed96-4f1d-9a14-1e3ca1863d74]
ibm_is_instance.waziaas_instances["tagtest02"]: Refreshing state... [id=02f7_472210fd-f6c4-4cea-9d17-a77ce422eb9a]
ibm_is_instance.waziaas_instances["tagtest01"]: Refreshing state... [id=02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f]
ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest02"]: Refreshing state... [id=02f7_472210fd-f6c4-4cea-9d17-a77ce422eb9a/02f7-9788f656-ec80-4226-98a1-b40a170a1024]
ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest01"]: Refreshing state... [id=02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f/02f7-5057a25c-8848-44fa-bb50-db5a8ebff99a]
ibm_is_instance_action.waziaas_action["tagtest01"]: Refreshing state... [id=02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f]
ibm_is_instance_action.waziaas_action["tagtest02"]: Refreshing state... [id=02f7_472210fd-f6c4-4cea-9d17-a77ce422eb9a]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  - destroy

Terraform will perform the following actions:

  # ibm_is_instance.waziaas_instances["tagtest01"] will be destroyed
  # (because key ["tagtest01"] is not in for_each map)
  - resource "ibm_is_instance" "waziaas_instances" {
      - access_tags                      = [] -> null
      - availability_policy_host_failure = "restart" -> null
      - bandwidth                        = 4000 -> null
      - crn                              = "crn:v1:bluemix:public:is:jp-tok-2:a/1fc8373f538a408187ffedbe62e5796a::instance:02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f" -> null
      - disks                            = [] -> null
      - force_action                     = false -> null
      - gpu                              = [] -> null
      - id                               = "02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f" -> null
      - image                            = "r022-7a175b16-59b2-476c-a246-da5e953fa722" -> null
      - keys                             = [
          - "r022-ae873e5b-8fdc-4ca4-bcf0-f8ef6b14fa40",
        ] -> null
      - lifecycle_reasons                = [] -> null
      - lifecycle_state                  = "stable" -> null
      - memory                           = 16 -> null
      - metadata_service_enabled         = false -> null
      - name                             = "tagtest01" -> null
      - placement_target                 = [] -> null
      - profile                          = "mz2-2x16" -> null
      - reservation                      = [] -> null
      - resource_controller_url          = "https://cloud.ibm.com/vpc-ext/compute/vs" -> null
      - resource_crn                     = "crn:v1:bluemix:public:is:jp-tok-2:a/1fc8373f538a408187ffedbe62e5796a::instance:02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f" -> null
      - resource_group                   = "07c38a522f014e74aa065dfe2ab7f9af" -> null
      - resource_group_name              = "ISEI20230707-1626-nervous" -> null
      - resource_name                    = "tagtest01" -> null
      - resource_status                  = "running" -> null
      - status                           = "running" -> null
      - status_reasons                   = [] -> null
      - tags                             = [] -> null
      - total_network_bandwidth          = 3000 -> null
      - total_volume_bandwidth           = 1000 -> null
      - vcpu                             = [
          - {
              - architecture = "s390x"
              - count        = 2
              - manufacturer = "ibm"
            },
        ] -> null
      - volume_attachments               = [
          - {
              - id          = "02f7-183a1902-5f9d-4842-b748-931d2cbc89af"
              - name        = "shoptalk-storewide-setup-gossip"
              - volume_crn  = "crn:v1:bluemix:public:is:jp-tok-2:a/1fc8373f538a408187ffedbe62e5796a::volume:r022-3b2f3f3f-06fa-463f-ad55-e3ac6af801e9"
              - volume_id   = "r022-3b2f3f3f-06fa-463f-ad55-e3ac6af801e9"
              - volume_name = "tagtest01-bootvol"
            },
          - {
              - id          = "02f7-5057a25c-8848-44fa-bb50-db5a8ebff99a"
              - name        = "tagtest01-datavol01"
              - volume_crn  = "crn:v1:bluemix:public:is:jp-tok-2:a/1fc8373f538a408187ffedbe62e5796a::volume:r022-5ccc3dc7-3ec9-4e57-854b-116010f671ae"
              - volume_id   = "r022-5ccc3dc7-3ec9-4e57-854b-116010f671ae"
              - volume_name = "tagtest01-datavol01"
            },
        ] -> null
      - vpc                              = "r022-a9e1fd5d-3911-4cd4-bfb0-032298831d34" -> null
      - wait_before_delete               = true -> null
      - zone                             = "jp-tok-2" -> null

      - boot_volume {
          - auto_delete_volume = true -> null
          - iops               = 3000 -> null
          - name               = "tagtest01-bootvol" -> null
          - profile            = "general-purpose" -> null
          - size               = 10 -> null
          - snapshot           = "r022-b4e4ea78-b27c-44a4-88a3-ba670100a4ec" -> null
          - tags               = [] -> null
          - volume_id          = "r022-3b2f3f3f-06fa-463f-ad55-e3ac6af801e9" -> null
        }

      - metadata_service {
          - enabled            = false -> null
          - protocol           = "http" -> null
          - response_hop_limit = 1 -> null
        }

      - primary_network_interface {
          - allow_ip_spoofing    = false -> null
          - id                   = "02f7-c65731d7-cc48-4966-8a06-c3185a017693" -> null
          - name                 = "latterly-apricot-detract-foe" -> null
          - port_speed           = 3000 -> null
          - primary_ipv4_address = "10.244.64.23" -> null
          - security_groups      = [
              - "r022-f29b5e82-e744-4694-82db-8535e3eabafa",
            ] -> null
          - subnet               = "02f7-e9aecd6a-ed96-4f1d-9a14-1e3ca1863d74" -> null

          - primary_ip {
              - address       = "10.244.64.23" -> null
              - auto_delete   = true -> null
              - href          = "https://jp-tok.iaas.cloud.ibm.com/v1/subnets/02f7-e9aecd6a-ed96-4f1d-9a14-1e3ca1863d74/reserved_ips/02f7-1e633a16-546c-4657-ae2f-e6c16dcc149d" -> null
              - name          = "unclog-map-snowless-repulsion" -> null
              - reserved_ip   = "02f7-1e633a16-546c-4657-ae2f-e6c16dcc149d" -> null
              - resource_type = "subnet_reserved_ip" -> null
            }
        }

      - reservation_affinity {
          - policy = "disabled" -> null
        }
    }

  # ibm_is_instance_action.waziaas_action["tagtest01"] will be destroyed
  # (because key ["tagtest01"] is not in for_each map)
  - resource "ibm_is_instance_action" "waziaas_action" {
      - action         = "reboot" -> null
      - force_action   = false -> null
      - id             = "02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f" -> null
      - instance       = "02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f" -> null
      - status         = "running" -> null
      - status_reasons = [] -> null
    }

  # ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest01"] will be destroyed
  # (because key ["tagtest01"] is not in for_each map)
  - resource "ibm_is_instance_volume_attachment" "waziaas_datavol01" {
      - capacity                           = 66 -> null
      - delete_volume_on_attachment_delete = true -> null
      - delete_volume_on_instance_delete   = true -> null
      - device                             = "02f7-5057a25c-8848-44fa-bb50-db5a8ebff99a-7gfv5" -> null
      - href                               = "https://jp-tok.iaas.cloud.ibm.com/v1/instances/02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f/volume_attachments/02f7-5057a25c-8848-44fa-bb50-db5a8ebff99a" -> null
      - id                                 = "02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f/02f7-5057a25c-8848-44fa-bb50-db5a8ebff99a" -> null
      - instance                           = "02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f" -> null
      - iops                               = 3000 -> null
      - name                               = "tagtest01-datavol01" -> null
      - profile                            = "general-purpose" -> null
      - snapshot                           = "r022-83ccc33d-4ac4-468a-8cc8-1d4198365802" -> null
      - status                             = "attached" -> null
      - tags                               = [] -> null
      - type                               = "data" -> null
      - volume                             = "r022-5ccc3dc7-3ec9-4e57-854b-116010f671ae" -> null
      - volume_attachment_id               = "02f7-5057a25c-8848-44fa-bb50-db5a8ebff99a" -> null
      - volume_crn                         = "crn:v1:bluemix:public:is:jp-tok-2:a/1fc8373f538a408187ffedbe62e5796a::volume:r022-5ccc3dc7-3ec9-4e57-854b-116010f671ae" -> null
      - volume_href                        = "https://jp-tok.iaas.cloud.ibm.com/v1/volumes/r022-5ccc3dc7-3ec9-4e57-854b-116010f671ae" -> null
      - volume_name                        = "tagtest01-datavol01" -> null
    }

Plan: 0 to add, 0 to change, 3 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

ibm_is_instance_action.waziaas_action["tagtest01"]: Destroying... [id=02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f]
ibm_is_instance_action.waziaas_action["tagtest01"]: Destruction complete after 0s
ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest01"]: Destroying... [id=02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f/02f7-5057a25c-8848-44fa-bb50-db5a8ebff99a]
ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest01"]: Still destroying... [id=02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae6...7-5057a25c-8848-44fa-bb50-db5a8ebff99a, 10s elapsed]
ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest01"]: Still destroying... [id=02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae6...7-5057a25c-8848-44fa-bb50-db5a8ebff99a, 20s elapsed]
ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest01"]: Destruction complete after 22s
ibm_is_instance.waziaas_instances["tagtest01"]: Destroying... [id=02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f]
ibm_is_instance.waziaas_instances["tagtest01"]: Still destroying... [id=02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f, 10s elapsed]
ibm_is_instance.waziaas_instances["tagtest01"]: Still destroying... [id=02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f, 20s elapsed]
ibm_is_instance.waziaas_instances["tagtest01"]: Still destroying... [id=02f7_c07aa8bf-4d0a-4da9-9b86-f780858ae61f, 30s elapsed]
ibm_is_instance.waziaas_instances["tagtest01"]: Destruction complete after 39s

Apply complete! Resources: 0 added, 0 changed, 3 destroyed.

状況確認 / terraform state

state
user01@IBM-PF3ALW3Q:~/Ansible/VSCode_workspace/my_terraform_wazi02$ terraform state list
data.ibm_is_security_group.secgrp_wazi_common
data.ibm_is_subnet.target_subnet
data.ibm_is_vpc.target_vpc
ibm_is_instance.waziaas_instances["tagtest02"]
ibm_is_instance_action.waziaas_action["tagtest02"]
ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest02"]
ibm_is_ssh_key.wazi_dummy
tls_private_key.ssh_key
IBM Cloud管理コンソールでの確認

image.png

image.png

破棄 / terraform destroy

全てのリソースを破棄します。

deploy
user01@IBM-PF3ALW3Q:~/Ansible/VSCode_workspace/my_terraform_wazi02$ terraform destroy
tls_private_key.ssh_key: Refreshing state... [id=12faf55a2fa0473690080a6fbdf150751684dfbc]
data.ibm_is_vpc.target_vpc: Reading...
ibm_is_ssh_key.wazi_dummy: Refreshing state... [id=r022-ae873e5b-8fdc-4ca4-bcf0-f8ef6b14fa40]
data.ibm_is_security_group.secgrp_wazi_common: Reading...
data.ibm_is_security_group.secgrp_wazi_common: Read complete after 7s [id=r022-f29b5e82-e744-4694-82db-8535e3eabafa]
data.ibm_is_vpc.target_vpc: Read complete after 7s [id=r022-a9e1fd5d-3911-4cd4-bfb0-032298831d34]
data.ibm_is_subnet.target_subnet: Reading...
data.ibm_is_subnet.target_subnet: Read complete after 1s [id=02f7-e9aecd6a-ed96-4f1d-9a14-1e3ca1863d74]
ibm_is_instance.waziaas_instances["tagtest02"]: Refreshing state... [id=02f7_472210fd-f6c4-4cea-9d17-a77ce422eb9a]
ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest02"]: Refreshing state... [id=02f7_472210fd-f6c4-4cea-9d17-a77ce422eb9a/02f7-9788f656-ec80-4226-98a1-b40a170a1024]
ibm_is_instance_action.waziaas_action["tagtest02"]: Refreshing state... [id=02f7_472210fd-f6c4-4cea-9d17-a77ce422eb9a]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  - destroy

Terraform will perform the following actions:

  # ibm_is_instance.waziaas_instances["tagtest02"] will be destroyed
  - resource "ibm_is_instance" "waziaas_instances" {
      - access_tags                      = [] -> null
      - availability_policy_host_failure = "restart" -> null
      - bandwidth                        = 4000 -> null
      - crn                              = "crn:v1:bluemix:public:is:jp-tok-2:a/1fc8373f538a408187ffedbe62e5796a::instance:02f7_472210fd-f6c4-4cea-9d17-a77ce422eb9a" -> null
      - disks                            = [] -> null
      - force_action                     = false -> null
      - gpu                              = [] -> null
      - id                               = "02f7_472210fd-f6c4-4cea-9d17-a77ce422eb9a" -> null
      - image                            = "r022-7a175b16-59b2-476c-a246-da5e953fa722" -> null
      - keys                             = [
          - "r022-ae873e5b-8fdc-4ca4-bcf0-f8ef6b14fa40",
        ] -> null
      - lifecycle_reasons                = [] -> null
      - lifecycle_state                  = "stable" -> null
      - memory                           = 16 -> null
      - metadata_service_enabled         = false -> null
      - name                             = "tagtest02" -> null
      - placement_target                 = [] -> null
      - profile                          = "mz2-2x16" -> null
      - reservation                      = [] -> null
      - resource_controller_url          = "https://cloud.ibm.com/vpc-ext/compute/vs" -> null
      - resource_crn                     = "crn:v1:bluemix:public:is:jp-tok-2:a/1fc8373f538a408187ffedbe62e5796a::instance:02f7_472210fd-f6c4-4cea-9d17-a77ce422eb9a" -> null
      - resource_group                   = "07c38a522f014e74aa065dfe2ab7f9af" -> null
      - resource_group_name              = "ISEI20230707-1626-nervous" -> null
      - resource_name                    = "tagtest02" -> null
      - resource_status                  = "running" -> null
      - status                           = "running" -> null
      - status_reasons                   = [] -> null
      - tags                             = [] -> null
      - total_network_bandwidth          = 3000 -> null
      - total_volume_bandwidth           = 1000 -> null
      - vcpu                             = [
          - {
              - architecture = "s390x"
              - count        = 2
              - manufacturer = "ibm"
            },
        ] -> null
      - volume_attachments               = [
          - {
              - id          = "02f7-ef9c134e-6fc2-46e6-a579-f5cbb34dbc90"
              - name        = "autoalarm-tropics-wrung-divinely"
              - volume_crn  = "crn:v1:bluemix:public:is:jp-tok-2:a/1fc8373f538a408187ffedbe62e5796a::volume:r022-2ea309a0-7d56-4e1b-b677-4ef5e7887236"
              - volume_id   = "r022-2ea309a0-7d56-4e1b-b677-4ef5e7887236"
              - volume_name = "tagtest02-bootvol"
            },
          - {
              - id          = "02f7-9788f656-ec80-4226-98a1-b40a170a1024"
              - name        = "tagtest02-datavol01"
              - volume_crn  = "crn:v1:bluemix:public:is:jp-tok-2:a/1fc8373f538a408187ffedbe62e5796a::volume:r022-b3fb7c97-de40-43c9-979a-34d09a9b643b"
              - volume_id   = "r022-b3fb7c97-de40-43c9-979a-34d09a9b643b"
              - volume_name = "tagtest02-datavol01"
            },
        ] -> null
      - vpc                              = "r022-a9e1fd5d-3911-4cd4-bfb0-032298831d34" -> null
      - wait_before_delete               = true -> null
      - zone                             = "jp-tok-2" -> null

      - boot_volume {
          - auto_delete_volume = true -> null
          - iops               = 3000 -> null
          - name               = "tagtest02-bootvol" -> null
          - profile            = "general-purpose" -> null
          - size               = 10 -> null
          - snapshot           = "r022-b4e4ea78-b27c-44a4-88a3-ba670100a4ec" -> null
          - tags               = [] -> null
          - volume_id          = "r022-2ea309a0-7d56-4e1b-b677-4ef5e7887236" -> null
        }

      - metadata_service {
          - enabled            = false -> null
          - protocol           = "http" -> null
          - response_hop_limit = 1 -> null
        }

      - primary_network_interface {
          - allow_ip_spoofing    = false -> null
          - id                   = "02f7-464b9390-1123-48f0-a83e-82fd58ae3741" -> null
          - name                 = "calf-revenge-shut-reprise" -> null
          - port_speed           = 3000 -> null
          - primary_ipv4_address = "10.244.64.25" -> null
          - security_groups      = [
              - "r022-f29b5e82-e744-4694-82db-8535e3eabafa",
            ] -> null
          - subnet               = "02f7-e9aecd6a-ed96-4f1d-9a14-1e3ca1863d74" -> null

          - primary_ip {
              - address       = "10.244.64.25" -> null
              - auto_delete   = true -> null
              - href          = "https://jp-tok.iaas.cloud.ibm.com/v1/subnets/02f7-e9aecd6a-ed96-4f1d-9a14-1e3ca1863d74/reserved_ips/02f7-9b015fa8-0e4a-49b6-a74f-e915bf67d71d" -> null
              - name          = "sincere-palpable-ducktail-kithe" -> null
              - reserved_ip   = "02f7-9b015fa8-0e4a-49b6-a74f-e915bf67d71d" -> null
              - resource_type = "subnet_reserved_ip" -> null
            }
        }

      - reservation_affinity {
          - policy = "disabled" -> null
        }
    }

  # ibm_is_instance_action.waziaas_action["tagtest02"] will be destroyed
  - resource "ibm_is_instance_action" "waziaas_action" {
      - action         = "reboot" -> null
      - force_action   = false -> null
      - id             = "02f7_472210fd-f6c4-4cea-9d17-a77ce422eb9a" -> null
      - instance       = "02f7_472210fd-f6c4-4cea-9d17-a77ce422eb9a" -> null
      - status         = "running" -> null
      - status_reasons = [] -> null
    }

  # ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest02"] will be destroyed
  - resource "ibm_is_instance_volume_attachment" "waziaas_datavol01" {
      - capacity                           = 66 -> null
      - delete_volume_on_attachment_delete = true -> null
      - delete_volume_on_instance_delete   = true -> null
      - device                             = "02f7-9788f656-ec80-4226-98a1-b40a170a1024-7854z" -> null
      - href                               = "https://jp-tok.iaas.cloud.ibm.com/v1/instances/02f7_472210fd-f6c4-4cea-9d17-a77ce422eb9a/volume_attachments/02f7-9788f656-ec80-4226-98a1-b40a170a1024" -> null
      - id                                 = "02f7_472210fd-f6c4-4cea-9d17-a77ce422eb9a/02f7-9788f656-ec80-4226-98a1-b40a170a1024" -> null
      - instance                           = "02f7_472210fd-f6c4-4cea-9d17-a77ce422eb9a" -> null
      - iops                               = 3000 -> null
      - name                               = "tagtest02-datavol01" -> null
      - profile                            = "general-purpose" -> null
      - snapshot                           = "r022-83ccc33d-4ac4-468a-8cc8-1d4198365802" -> null
      - status                             = "attached" -> null
      - tags                               = [] -> null
      - type                               = "data" -> null
      - volume                             = "r022-b3fb7c97-de40-43c9-979a-34d09a9b643b" -> null
      - volume_attachment_id               = "02f7-9788f656-ec80-4226-98a1-b40a170a1024" -> null
      - volume_crn                         = "crn:v1:bluemix:public:is:jp-tok-2:a/1fc8373f538a408187ffedbe62e5796a::volume:r022-b3fb7c97-de40-43c9-979a-34d09a9b643b" -> null
      - volume_href                        = "https://jp-tok.iaas.cloud.ibm.com/v1/volumes/r022-b3fb7c97-de40-43c9-979a-34d09a9b643b" -> null
      - volume_name                        = "tagtest02-datavol01" -> null
    }

  # ibm_is_ssh_key.wazi_dummy will be destroyed
  - resource "ibm_is_ssh_key" "wazi_dummy" {
      - access_tags             = [] -> null
      - crn                     = "crn:v1:bluemix:public:is:jp-tok:a/1fc8373f538a408187ffedbe62e5796a::key:r022-ae873e5b-8fdc-4ca4-bcf0-f8ef6b14fa40" -> null
      - fingerprint             = "SHA256:FTWNR4TeUEG4x+Xc1Nkm8Rea7HrX4HRMLmlafxxQorY" -> null
      - id                      = "r022-ae873e5b-8fdc-4ca4-bcf0-f8ef6b14fa40" -> null
      - length                  = 2048 -> null
      - name                    = "wazi-dummy" -> null
      - public_key              = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCr1/Uti2bBOcafJxAr3qdqdVybnhx3uIuL+5g6QM5TDVWDBR+PtDyuyI7+iUzCN3vs3fB9/v0wPE1WT9NX69X6JfazOTjvHsyhzKpxUxvBAWj3lqERaHe1bAGsM803y11jPC83+SPzePJrB307TYCarintMnl7wyj5/r4meNDUY17jVH/rJ6/TY1VF8Qw82M6QseeIV6LKOVv29hZMeASv2z/0sV72N0arwMxjrpbEDfJ9Cpt19ZP6vy1ZVBwbgqRIvBOksbiIrqtGPaTCl2BMJcyknuMNl6EKejysskC12soEVbUXkugY7Fbo8j9jhEJ119FTUMnbC/RPb/FxMEnB" -> null
      - resource_controller_url = "https://cloud.ibm.com/vpc-ext/compute/sshKeys" -> null
      - resource_crn            = "crn:v1:bluemix:public:is:jp-tok:a/1fc8373f538a408187ffedbe62e5796a::key:r022-ae873e5b-8fdc-4ca4-bcf0-f8ef6b14fa40" -> null
      - resource_group          = "07c38a522f014e74aa065dfe2ab7f9af" -> null
      - resource_group_name     = "ISEI20230707-1626-nervous" -> null
      - resource_name           = "wazi-dummy" -> null
      - tags                    = [] -> null
      - type                    = "rsa" -> null
    }

  # tls_private_key.ssh_key will be destroyed
  - resource "tls_private_key" "ssh_key" {
      - algorithm                     = "RSA" -> null
      - ecdsa_curve                   = "P224" -> null
      - id                            = "12faf55a2fa0473690080a6fbdf150751684dfbc" -> null
      - private_key_openssh           = (sensitive value) -> null
      - private_key_pem               = (sensitive value) -> null
      - private_key_pem_pkcs8         = (sensitive value) -> null
      - public_key_fingerprint_md5    = "7b:10:87:85:02:0f:22:b6:56:f0:d3:cd:a1:0e:de:4e" -> null
      - public_key_fingerprint_sha256 = "SHA256:FTWNR4TeUEG4x+Xc1Nkm8Rea7HrX4HRMLmlafxxQorY" -> null
      - public_key_openssh            = <<-EOT
            ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCr1/Uti2bBOcafJxAr3qdqdVybnhx3uIuL+5g6QM5TDVWDBR+PtDyuyI7+iUzCN3vs3fB9/v0wPE1WT9NX69X6JfazOTjvHsyhzKpxUxvBAWj3lqERaHe1bAGsM803y11jPC83+SPzePJrB307TYCarintMnl7wyj5/r4meNDUY17jVH/rJ6/TY1VF8Qw82M6QseeIV6LKOVv29hZMeASv2z/0sV72N0arwMxjrpbEDfJ9Cpt19ZP6vy1ZVBwbgqRIvBOksbiIrqtGPaTCl2BMJcyknuMNl6EKejysskC12soEVbUXkugY7Fbo8j9jhEJ119FTUMnbC/RPb/FxMEnB
        EOT -> null
      - public_key_pem                = <<-EOT
            -----BEGIN PUBLIC KEY-----
            MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAq9f1LYtmwTnGnycQK96n
            anVcm54cd7iLi/uYOkDOUw1VgwUfj7Q8rsiO/olMwjd77N3wff79MDxNVk/TV+vV
            +iX2szk47x7MocyqcVMbwQFo95ahEWh3tWwBrDPNN8tdYzwvN/kj83jyawd9O02A
            mq4p7TJ5e8Mo+f6+JnjQ1GNe41R/6yev02NVRfEMPNjOkLHniFeiyjlb9vYWTHgE
            r9s/9LFe9jdGq8DMY66WxA3yfQqbdfWT+r8tWVQcG4KkSLwTpLG4iK6rRj2kwpdg
            TCXMpJ7jDZehCno8rLJAtdrKBFW1F5LoGOxW6PI/Y4RCddfRU1DJ2wv0T2/xcTBJ
            wQIDAQAB
            -----END PUBLIC KEY-----
        EOT -> null
      - rsa_bits                      = 2048 -> null
    }

Plan: 0 to add, 0 to change, 5 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

ibm_is_instance_action.waziaas_action["tagtest02"]: Destroying... [id=02f7_472210fd-f6c4-4cea-9d17-a77ce422eb9a]
ibm_is_instance_action.waziaas_action["tagtest02"]: Destruction complete after 0s
ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest02"]: Destroying... [id=02f7_472210fd-f6c4-4cea-9d17-a77ce422eb9a/02f7-9788f656-ec80-4226-98a1-b40a170a1024]
ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest02"]: Still destroying... [id=02f7_472210fd-f6c4-4cea-9d17-a77ce422eb...7-9788f656-ec80-4226-98a1-b40a170a1024, 10s elapsed]
ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest02"]: Still destroying... [id=02f7_472210fd-f6c4-4cea-9d17-a77ce422eb...7-9788f656-ec80-4226-98a1-b40a170a1024, 20s elapsed]
ibm_is_instance_volume_attachment.waziaas_datavol01["tagtest02"]: Destruction complete after 22s
ibm_is_instance.waziaas_instances["tagtest02"]: Destroying... [id=02f7_472210fd-f6c4-4cea-9d17-a77ce422eb9a]
ibm_is_instance.waziaas_instances["tagtest02"]: Still destroying... [id=02f7_472210fd-f6c4-4cea-9d17-a77ce422eb9a, 10s elapsed]
ibm_is_instance.waziaas_instances["tagtest02"]: Still destroying... [id=02f7_472210fd-f6c4-4cea-9d17-a77ce422eb9a, 20s elapsed]
ibm_is_instance.waziaas_instances["tagtest02"]: Still destroying... [id=02f7_472210fd-f6c4-4cea-9d17-a77ce422eb9a, 30s elapsed]
ibm_is_instance.waziaas_instances["tagtest02"]: Destruction complete after 36s
ibm_is_ssh_key.wazi_dummy: Destroying... [id=r022-ae873e5b-8fdc-4ca4-bcf0-f8ef6b14fa40]
ibm_is_ssh_key.wazi_dummy: Destruction complete after 4s
tls_private_key.ssh_key: Destroying... [id=12faf55a2fa0473690080a6fbdf150751684dfbc]
tls_private_key.ssh_key: Destruction complete after 0s

Destroy complete! Resources: 5 destroyed.

おわりに

スナップショットをベースにWazi aaS仮想サーバーのインスタンスを追加/削除する管理がTerraformによりスマートに行えることが確認できました。
1つのWazi aaSインスタンスをテンプレート環境(メンテナンス用)として用意しておき、必要に応じてその複製を柔軟に追加/削除するという運用に利用できると思います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0