[Azure]VMインスタンスを作成しSSH接続してみる(Terraform)

投稿者: | 2025年8月9日

こちらの記事で Azure Portal を使用して Azure 環境で VM を立ち上げ、ローカルのWindowsマシンからSSH接続してみました。

今回は同じ構成で、インフラはTerraformを使って構築し、VMにSSHで接続してみます。

前提

ローカルのWindows環境でTerraformを使用します。

以下のサイトからTerraformをダウンロードして解凍します。

https://developer.hashicorp.com/terraform/install

解凍して得られたフォルダにある terraform.exe に環境変数でパスを通しておきましょう。

SSHキーの作成

後で立ち上げるVMに接続するためのSSHキーを作成しておきます。

コマンドプロンプトから以下を実行。

ssh-keygen -t rsa -b 4096 -f .ssh\id_rsa

実行時のカレントディレクトリにある .ssh フォルダに、公開鍵と秘密鍵が作成されます。

Terraformのフォルダ構成

任意の場所に、以下のフォルダ構成でTerraformのファイルを作成していきます。今回はCドライブ直下に作成。

terraform-azure-vm/
├── main.tf
├── variables.tf
└── terraform.tfvars

main.tf

providerブロックにある subscription_id には、使用するサブスクリプションのIDを設定しておきます。

provider "azurerm" {
  features {}
  subscription_id = "xxxxxxxxxxxxxxxxxxxxxx"
}

resource "azurerm_resource_group" "rg" {
  name     = var.resource_group_name
  location = var.location
}

resource "azurerm_virtual_network" "vnet" {
  name                = "example-vnet"
  address_space       = ["10.0.0.0/16"]
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name
}

resource "azurerm_subnet" "subnet" {
  name                 = "example-subnet"
  resource_group_name  = azurerm_resource_group.rg.name
  virtual_network_name = azurerm_virtual_network.vnet.name
  address_prefixes     = ["10.0.1.0/24"]
}

resource "azurerm_public_ip" "public_ip" {
  name                = "example-pip"
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name
  allocation_method   = "Dynamic"
  sku                 = "Basic"
}

resource "azurerm_network_interface" "nic" {
  name                = "example-nic"
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name

  ip_configuration {
    name                          = "internal"
    subnet_id                     = azurerm_subnet.subnet.id
    private_ip_address_allocation = "Dynamic"
    public_ip_address_id          = azurerm_public_ip.public_ip.id
  }
}

resource "azurerm_linux_virtual_machine" "vm" {
  name                = "example-vm"
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name
  size                = "Standard_B1s"
  admin_username      = var.admin_username
  network_interface_ids = [
    azurerm_network_interface.nic.id,
  ]
  admin_ssh_key {
    username   = var.admin_username
    public_key = file(var.ssh_public_key)
  }
  os_disk {
    caching              = "ReadWrite"
    storage_account_type = "Standard_LRS"
  }
  source_image_reference {
    publisher = "Canonical"
    offer     = "UbuntuServer"
    sku       = "18.04-LTS"
    version   = "latest"
  }
}

variables.tf

variable "resource_group_name" {
  type        = string
  default     = "example-rg"
}

variable "location" {
  type        = string
  default     = "japaneast"
}

variable "admin_username" {
  type        = string
  default     = "azureuser"
}

variable "ssh_public_key" {
  type        = string
  description = "Path to your SSH public key"
}

terraform.tfvars

このファイルには、先に作成した公開鍵のフルパスを指定しておきます。

ssh_public_key = "C:\\[.sshがあるフォルダパス]\\.ssh\\id_rsa.pub"

Azureにログイン

以下のコマンドでAzureにログインしておきます。

az login

テナントIDの指定が必要になるケースがあります。

初期化(terraform init)

“terraform init” コマンドで、Terraformを初期化します。

実行は、先に作成したファイルが存在するディレクトリで行います。

C:\terraform-azure-vm>terraform init
Initializing the backend...
Initializing provider plugins...
- Finding latest version of hashicorp/azurerm...
- Installing hashicorp/azurerm v4.38.1...
- Installed hashicorp/azurerm v4.38.1 (signed by HashiCorp)
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)

“terraform plan”コマンドで、手を入れるリソースを確認できます。

実環境に影響はないですが、リソース変更前のチェックに使用します。

C:\terraform-azure-vm>terraform plan

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:

  # azurerm_linux_virtual_machine.vm will be created
  + resource "azurerm_linux_virtual_machine" "vm" {
      + admin_username                                         = "azureuser"
      + allow_extension_operations                             = true
      + bypass_platform_safety_checks_on_user_schedule_enabled = false
      + computer_name                                          = (known after apply)
      + disable_password_authentication                        = true
      + disk_controller_type                                   = (known after apply)
      + extensions_time_budget                                 = "PT1H30M"
      + id                                                     = (known after apply)
      + location                                               = "japaneast"
      + max_bid_price                                          = -1
      + name                                                   = "example-vm"
      + network_interface_ids                                  = (known after apply)
      + patch_assessment_mode                                  = "ImageDefault"
      + patch_mode                                             = "ImageDefault"
      + platform_fault_domain                                  = -1
      + priority                                               = "Regular"
      + private_ip_address                                     = (known after apply)
      + private_ip_addresses                                   = (known after apply)
      + provision_vm_agent                                     = true
      + public_ip_address                                      = (known after apply)
      + public_ip_addresses                                    = (known after apply)
      + resource_group_name                                    = "example-rg"
      + size                                                   = "Standard_B1s"
      + virtual_machine_id                                     = (known after apply)
      + vm_agent_platform_updates_enabled                      = (known after apply)

      + admin_ssh_key {
          + public_key = <<-EOT
                ssh-rsa XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX== xxxxxx@xxxxxx
            EOT
          + username   = "azureuser"
        }

      + os_disk {
          + caching                   = "ReadWrite"
          + disk_size_gb              = (known after apply)
          + id                        = (known after apply)
          + name                      = (known after apply)
          + storage_account_type      = "Standard_LRS"
          + write_accelerator_enabled = false
        }

      + source_image_reference {
          + offer     = "UbuntuServer"
          + publisher = "Canonical"
          + sku       = "18.04-LTS"
          + version   = "latest"
        }

      + termination_notification (known after apply)
    }

  # azurerm_network_interface.nic will be created
  + resource "azurerm_network_interface" "nic" {
      + accelerated_networking_enabled = false
      + applied_dns_servers            = (known after apply)
      + id                             = (known after apply)
      + internal_domain_name_suffix    = (known after apply)
      + ip_forwarding_enabled          = false
      + location                       = "japaneast"
      + mac_address                    = (known after apply)
      + name                           = "example-nic"
      + private_ip_address             = (known after apply)
      + private_ip_addresses           = (known after apply)
      + resource_group_name            = "example-rg"
      + virtual_machine_id             = (known after apply)

      + ip_configuration {
          + gateway_load_balancer_frontend_ip_configuration_id = (known after apply)
          + name                                               = "internal"
          + primary                                            = (known after apply)
          + private_ip_address                                 = (known after apply)
          + private_ip_address_allocation                      = "Dynamic"
          + private_ip_address_version                         = "IPv4"
          + public_ip_address_id                               = (known after apply)
          + subnet_id                                          = (known after apply)
        }
    }

  # azurerm_public_ip.public_ip will be created
  + resource "azurerm_public_ip" "public_ip" {
      + allocation_method       = "Dynamic"
      + ddos_protection_mode    = "VirtualNetworkInherited"
      + fqdn                    = (known after apply)
      + id                      = (known after apply)
      + idle_timeout_in_minutes = 4
      + ip_address              = (known after apply)
      + ip_version              = "IPv4"
      + location                = "japaneast"
      + name                    = "example-pip"
      + resource_group_name     = "example-rg"
      + sku                     = "Basic"
      + sku_tier                = "Regional"
    }

  # azurerm_resource_group.rg will be created
  + resource "azurerm_resource_group" "rg" {
      + id       = (known after apply)
      + location = "japaneast"
      + name     = "example-rg"
    }

  # azurerm_subnet.subnet will be created
  + resource "azurerm_subnet" "subnet" {
      + address_prefixes                              = [
          + "10.0.1.0/24",
        ]
      + default_outbound_access_enabled               = true
      + id                                            = (known after apply)
      + name                                          = "example-subnet"
      + private_endpoint_network_policies             = "Disabled"
      + private_link_service_network_policies_enabled = true
      + resource_group_name                           = "example-rg"
      + virtual_network_name                          = "example-vnet"
    }

  # azurerm_virtual_network.vnet will be created
  + resource "azurerm_virtual_network" "vnet" {
      + address_space                  = [
          + "10.0.0.0/16",
        ]
      + dns_servers                    = (known after apply)
      + guid                           = (known after apply)
      + id                             = (known after apply)
      + location                       = "japaneast"
      + name                           = "example-vnet"
      + private_endpoint_vnet_policies = "Disabled"
      + resource_group_name            = "example-rg"
      + subnet                         = (known after apply)
    }

Plan: 6 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”コマンドでAzureにリソースを作成していきます。

C:\terraform-azure-vm>terraform apply

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:

  # azurerm_linux_virtual_machine.vm will be created
  + resource "azurerm_linux_virtual_machine" "vm" {
      + admin_username                                         = "azureuser"
      + allow_extension_operations                             = true
      + bypass_platform_safety_checks_on_user_schedule_enabled = false
      + computer_name                                          = (known after apply)
      + disable_password_authentication                        = true
      + disk_controller_type                                   = (known after apply)
      + extensions_time_budget                                 = "PT1H30M"
      + id                                                     = (known after apply)
      + location                                               = "japaneast"
      + max_bid_price                                          = -1
      + name                                                   = "example-vm"
      + network_interface_ids                                  = (known after apply)
      + patch_assessment_mode                                  = "ImageDefault"
      + patch_mode                                             = "ImageDefault"
      + platform_fault_domain                                  = -1
      + priority                                               = "Regular"
      + private_ip_address                                     = (known after apply)
      + private_ip_addresses                                   = (known after apply)
      + provision_vm_agent                                     = true
      + public_ip_address                                      = (known after apply)
      + public_ip_addresses                                    = (known after apply)
      + resource_group_name                                    = "example-rg"
      + size                                                   = "Standard_B1s"
      + virtual_machine_id                                     = (known after apply)
      + vm_agent_platform_updates_enabled                      = (known after apply)

      + admin_ssh_key {
          + public_key = <<-EOT
                ssh-rsa XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX== xxxxxx@xxxxxx
            EOT
          + username   = "azureuser"
        }

      + os_disk {
          + caching                   = "ReadWrite"
          + disk_size_gb              = (known after apply)
          + id                        = (known after apply)
          + name                      = (known after apply)
          + storage_account_type      = "Standard_LRS"
          + write_accelerator_enabled = false
        }

      + source_image_reference {
          + offer     = "UbuntuServer"
          + publisher = "Canonical"
          + sku       = "18.04-LTS"
          + version   = "latest"
        }

      + termination_notification (known after apply)
    }

  # azurerm_network_interface.nic will be created
  + resource "azurerm_network_interface" "nic" {
      + accelerated_networking_enabled = false
      + applied_dns_servers            = (known after apply)
      + id                             = (known after apply)
      + internal_domain_name_suffix    = (known after apply)
      + ip_forwarding_enabled          = false
      + location                       = "japaneast"
      + mac_address                    = (known after apply)
      + name                           = "example-nic"
      + private_ip_address             = (known after apply)
      + private_ip_addresses           = (known after apply)
      + resource_group_name            = "example-rg"
      + virtual_machine_id             = (known after apply)

      + ip_configuration {
          + gateway_load_balancer_frontend_ip_configuration_id = (known after apply)
          + name                                               = "internal"
          + primary                                            = (known after apply)
          + private_ip_address                                 = (known after apply)
          + private_ip_address_allocation                      = "Dynamic"
          + private_ip_address_version                         = "IPv4"
          + public_ip_address_id                               = (known after apply)
          + subnet_id                                          = (known after apply)
        }
    }

  # azurerm_public_ip.public_ip will be created
  + resource "azurerm_public_ip" "public_ip" {
      + allocation_method       = "Dynamic"
      + ddos_protection_mode    = "VirtualNetworkInherited"
      + fqdn                    = (known after apply)
      + id                      = (known after apply)
      + idle_timeout_in_minutes = 4
      + ip_address              = (known after apply)
      + ip_version              = "IPv4"
      + location                = "japaneast"
      + name                    = "example-pip"
      + resource_group_name     = "example-rg"
      + sku                     = "Standard"
      + sku_tier                = "Regional"
    }

  # azurerm_resource_group.rg will be created
  + resource "azurerm_resource_group" "rg" {
      + id       = (known after apply)
      + location = "japaneast"
      + name     = "example-rg"
    }

  # azurerm_subnet.subnet will be created
  + resource "azurerm_subnet" "subnet" {
      + address_prefixes                              = [
          + "10.0.1.0/24",
        ]
      + default_outbound_access_enabled               = true
      + id                                            = (known after apply)
      + name                                          = "example-subnet"
      + private_endpoint_network_policies             = "Disabled"
      + private_link_service_network_policies_enabled = true
      + resource_group_name                           = "example-rg"
      + virtual_network_name                          = "example-vnet"
    }

  # azurerm_virtual_network.vnet will be created
  + resource "azurerm_virtual_network" "vnet" {
      + address_space                  = [
          + "10.0.0.0/16",
        ]
      + dns_servers                    = (known after apply)
      + guid                           = (known after apply)
      + id                             = (known after apply)
      + location                       = "japaneast"
      + name                           = "example-vnet"
      + private_endpoint_vnet_policies = "Disabled"
      + resource_group_name            = "example-rg"
      + subnet                         = (known after apply)
    }

Plan: 6 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” と入力。作成が開始されます。

  Enter a value : yes

azurerm_resource_group.rg: Creating...
azurerm_resource_group.rg: Still creating... [00m10s elapsed]
azurerm_resource_group.rg: Creation complete after 12s [id=/subscriptions/[subscription id]/resourceGroups/example-rg]
azurerm_virtual_network.vnet: Creating...
azurerm_public_ip.public_ip: Creating...
azurerm_virtual_network.vnet: Creation complete after 5s [id=/subscriptions/[subscription id]/resourceGroups/example-rg/providers/Microsoft.Network/virtualNetworks/example-vnet]
azurerm_subnet.subnet: Creating...
azurerm_subnet.subnet: Creation complete after 6s [id=/subscriptions/[subscription id]/resourceGroups/example-rg/providers/Microsoft.Network/virtualNetworks/example-vnet/subnets/example-subnet]
azurerm_public_ip.public_ip: Creating...
azurerm_public_ip.public_ip: Creation complete after 2s [id=/subscriptions/[subscription id]/resourceGroups/example-rg/providers/Microsoft.Network/publicIPAddresses/example-pip]
azurerm_network_interface.nic: Creating...
azurerm_network_interface.nic: Still creating... [00m10s elapsed]
azurerm_network_interface.nic: Creation complete after 11s [id=/subscriptions/[subscription id]/resourceGroups/example-rg/providers/Microsoft.Network/networkInterfaces/example-nic]
azurerm_linux_virtual_machine.vm: Creating...
azurerm_linux_virtual_machine.vm: Still creating... [00m10s elapsed]
azurerm_linux_virtual_machine.vm: Still creating... [00m20s elapsed]
azurerm_linux_virtual_machine.vm: Still creating... [00m30s elapsed]
azurerm_linux_virtual_machine.vm: Still creating... [00m40s elapsed]
azurerm_linux_virtual_machine.vm: Creation complete after 49s [id=/subscriptions/[subscription id]/resourceGroups/example-rg/providers/Microsoft.Compute/virtualMachines/example-vm]

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

Azure portalでも作成されたリソースを確認できました。

VMにSSH接続

ローカルから以下のコマンドでSSH接続します。事前にパブリックIPアドレスを確認しておきましょう。

ssh azureuser@[public ip]

接続できました。

Welcome to Ubuntu 18.04.6 LTS (GNU/Linux 5.4.0-1109-azure x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Sat Aug  9 06:31:55 UTC 2025

  System load:  0.35              Processes:           111
  Usage of /:   4.5% of 28.89GB   Users logged in:     0
  Memory usage: 22%               IP address for eth0: 10.0.1.4
  Swap usage:   0%

Expanded Security Maintenance for Infrastructure is not enabled.

0 updates can be applied immediately.

Enable ESM Infra to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status



The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

azureuser@example-vm:~$

後片付け(terraform destroy)

リソース消費による課金を抑えるため、作成したリソースは”terraform destroy”で削除しておきます。

C:\terraform-azure-vm>terraform destroy
azurerm_resource_group.rg: Refreshing state... [id=/subscriptions/[subscription id]/resourceGroups/example-rg]
azurerm_public_ip.public_ip: Refreshing state... [id=/subscriptions/[subscription id]/resourceGroups/example-rg/providers/Microsoft.Network/publicIPAddresses/example-pip]
azurerm_virtual_network.vnet: Refreshing state... [id=/subscriptions/[subscription id]/resourceGroups/example-rg/providers/Microsoft.Network/virtualNetworks/example-vnet]
azurerm_subnet.subnet: Refreshing state... [id=/subscriptions/[subscription id]/resourceGroups/example-rg/providers/Microsoft.Network/virtualNetworks/example-vnet/subnets/example-subnet]
azurerm_network_interface.nic: Refreshing state... [id=/subscriptions/[subscription id]/resourceGroups/example-rg/providers/Microsoft.Network/networkInterfaces/example-nic]
azurerm_linux_virtual_machine.vm: Refreshing state... [id=/subscriptions/[subscription id]/resourceGroups/example-rg/providers/Microsoft.Compute/virtualMachines/example-vm]

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:

  # azurerm_linux_virtual_machine.vm will be destroyed
  - resource "azurerm_linux_virtual_machine" "vm" {
      - admin_username                                         = "azureuser" -> null
      - allow_extension_operations                             = true -> null
      - bypass_platform_safety_checks_on_user_schedule_enabled = false -> null
      - computer_name                                          = "example-vm" -> null
      - disable_password_authentication                        = true -> null
      - encryption_at_host_enabled                             = false -> null
      - extensions_time_budget                                 = "PT1H30M" -> null
      - id                                                     = "/subscriptions/[subscription id]/resourceGroups/example-rg/providers/Microsoft.Compute/virtualMachines/example-vm" -> null
      - location                                               = "japaneast" -> null
      - max_bid_price                                          = -1 -> null
      - name                                                   = "example-vm" -> null
      - network_interface_ids                                  = [
          - "/subscriptions/[subscription id]/resourceGroups/example-rg/providers/Microsoft.Network/networkInterfaces/example-nic",
        ] -> null
      - patch_assessment_mode                                  = "ImageDefault" -> null
      - patch_mode                                             = "ImageDefault" -> null
      - platform_fault_domain                                  = -1 -> null
      - priority                                               = "Regular" -> null
      - private_ip_address                                     = "10.0.1.4" -> null
      - private_ip_addresses                                   = [
          - "10.0.1.4",
        ] -> null
      - provision_vm_agent                                     = true -> null
      - public_ip_address                                      = "[public ip]" -> null
      - public_ip_addresses                                    = [
          - "[public ip]",
        ] -> null
      - resource_group_name                                    = "example-rg" -> null
      - secure_boot_enabled                                    = false -> null
      - size                                                   = "Standard_B1s" -> null
      - tags                                                   = {} -> null
      - virtual_machine_id                                     = "ba3a77db-eb98-4fc7-be8c-481eab9e2cca" -> null
      - vm_agent_platform_updates_enabled                      = false -> null
      - vtpm_enabled                                           = false -> null
        # (14 unchanged attributes hidden)

      - admin_ssh_key {
          - public_key = <<-EOT
                ssh-rsa XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX== xxxxxx@xxxxxx
            EOT -> null
          - username   = "azureuser" -> null
        }

      - os_disk {
          - caching                          = "ReadWrite" -> null
          - disk_size_gb                     = 30 -> null
          - id                               = "/subscriptions/[subscription id]/resourceGroups/example-rg/providers/Microsoft.Compute/disks/example-vm_OsDisk_1_117729c12848449bb4a25bddbaabf536" -> null
          - name                             = "example-vm_OsDisk_1_117729c12848449bb4a25bddbaabf536" -> null
          - storage_account_type             = "Standard_LRS" -> null
          - write_accelerator_enabled        = false -> null
            # (3 unchanged attributes hidden)
        }

      - source_image_reference {
          - offer     = "UbuntuServer" -> null
          - publisher = "Canonical" -> null
          - sku       = "18.04-LTS" -> null
          - version   = "latest" -> null
        }
    }

  # azurerm_network_interface.nic will be destroyed
  - resource "azurerm_network_interface" "nic" {
      - accelerated_networking_enabled = false -> null
      - applied_dns_servers            = [] -> null
      - dns_servers                    = [] -> null
      - id                             = "/subscriptions/[subscription id]/resourceGroups/example-rg/providers/Microsoft.Network/networkInterfaces/example-nic" -> null
      - internal_domain_name_suffix    = "bu1uy3l0jdsuto0zfbjt0trd3b.lx.internal.cloudapp.net" -> null
      - ip_forwarding_enabled          = false -> null
      - location                       = "japaneast" -> null
      - mac_address                    = "60-45-BD-65-51-1D" -> null
      - name                           = "example-nic" -> null
      - private_ip_address             = "10.0.1.4" -> null
      - private_ip_addresses           = [
          - "10.0.1.4",
        ] -> null
      - resource_group_name            = "example-rg" -> null
      - tags                           = {} -> null
      - virtual_machine_id             = "/subscriptions/[subscription id]/resourceGroups/example-rg/providers/Microsoft.Compute/virtualMachines/example-vm" -> null
        # (4 unchanged attributes hidden)

      - ip_configuration {
          - name                                               = "internal" -> null
          - primary                                            = true -> null
          - private_ip_address                                 = "10.0.1.4" -> null
          - private_ip_address_allocation                      = "Dynamic" -> null
          - private_ip_address_version                         = "IPv4" -> null
          - public_ip_address_id                               = "/subscriptions/[subscription id]/resourceGroups/example-rg/providers/Microsoft.Network/publicIPAddresses/example-pip" -> null
          - subnet_id                                          = "/subscriptions/[subscription id]/resourceGroups/example-rg/providers/Microsoft.Network/virtualNetworks/example-vnet/subnets/example-subnet" -> null
            # (1 unchanged attribute hidden)
        }
    }

  # azurerm_public_ip.public_ip will be destroyed
  - resource "azurerm_public_ip" "public_ip" {
      - allocation_method       = "Dynamic" -> null
      - ddos_protection_mode    = "VirtualNetworkInherited" -> null
      - id                      = "/subscriptions/[subscription id]/resourceGroups/example-rg/providers/Microsoft.Network/publicIPAddresses/example-pip" -> null
      - idle_timeout_in_minutes = 4 -> null
      - ip_address              = "[public ip]" -> null
      - ip_tags                 = {} -> null
      - ip_version              = "IPv4" -> null
      - location                = "japaneast" -> null
      - name                    = "example-pip" -> null
      - resource_group_name     = "example-rg" -> null
      - sku                     = "Basic" -> null
      - sku_tier                = "Regional" -> null
      - tags                    = {} -> null
      - zones                   = [] -> null
        # (1 unchanged attribute hidden)
    }

  # azurerm_resource_group.rg will be destroyed
  - resource "azurerm_resource_group" "rg" {
      - id         = "/subscriptions/[subscription id]/resourceGroups/example-rg" -> null
      - location   = "japaneast" -> null
      - name       = "example-rg" -> null
      - tags       = {} -> null
        # (1 unchanged attribute hidden)
    }

  # azurerm_subnet.subnet will be destroyed
  - resource "azurerm_subnet" "subnet" {
      - address_prefixes                              = [
          - "10.0.1.0/24",
        ] -> null
      - default_outbound_access_enabled               = true -> null
      - id                                            = "/subscriptions/[subscription id]/resourceGroups/example-rg/providers/Microsoft.Network/virtualNetworks/example-vnet/subnets/example-subnet" -> null
      - name                                          = "example-subnet" -> null
      - private_endpoint_network_policies             = "Disabled" -> null
      - private_link_service_network_policies_enabled = true -> null
      - resource_group_name                           = "example-rg" -> null
      - service_endpoint_policy_ids                   = [] -> null
      - service_endpoints                             = [] -> null
      - virtual_network_name                          = "example-vnet" -> null
    }

  # azurerm_virtual_network.vnet will be destroyed
  - resource "azurerm_virtual_network" "vnet" {
      - address_space                  = [
          - "10.0.0.0/16",
        ] -> null
      - dns_servers                    = [] -> null
      - flow_timeout_in_minutes        = 0 -> null
      - guid                           = "754c370d-487a-49e5-bb59-28533d4e23e9" -> null
      - id                             = "/subscriptions/[subscription id]/resourceGroups/example-rg/providers/Microsoft.Network/virtualNetworks/example-vnet" -> null
      - location                       = "japaneast" -> null
      - name                           = "example-vnet" -> null
      - private_endpoint_vnet_policies = "Disabled" -> null
      - resource_group_name            = "example-rg" -> null
      - subnet                         = [
          - {
              - address_prefixes                              = [
                  - "10.0.1.0/24",
                ]
              - default_outbound_access_enabled               = true
              - delegation                                    = []
              - id                                            = "/subscriptions/[subscription id]/resourceGroups/example-rg/providers/Microsoft.Network/virtualNetworks/example-vnet/subnets/example-subnet"
              - name                                          = "example-subnet"
              - private_endpoint_network_policies             = "Disabled"
              - private_link_service_network_policies_enabled = true
              - service_endpoint_policy_ids                   = []
              - service_endpoints                             = []
                # (2 unchanged attributes hidden)
            },
        ] -> null
      - tags                           = {} -> null
        # (2 unchanged attributes hidden)
    }

Plan: 0 to add, 0 to change, 6 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” を入力。削除が開始されます。

  Enter a value: yes

azurerm_linux_virtual_machine.vm: Destroying... [id=/subscriptions/[subscription id]/resourceGroups/example-rg/providers/Microsoft.Compute/virtualMachines/example-vm]
azurerm_linux_virtual_machine.vm: Still destroying... [id=/subscriptions/[subscription id]...oft.Compute/virtualMachines/example-vm, 00m10s elapsed]
azurerm_linux_virtual_machine.vm: Still destroying... [id=/subscriptions/[subscription id]...oft.Compute/virtualMachines/example-vm, 00m20s elapsed]
azurerm_linux_virtual_machine.vm: Still destroying... [id=/subscriptions/[subscription id]...oft.Compute/virtualMachines/example-vm, 00m30s elapsed]
azurerm_linux_virtual_machine.vm: Still destroying... [id=/subscriptions/[subscription id]...oft.Compute/virtualMachines/example-vm, 00m40s elapsed]
azurerm_linux_virtual_machine.vm: Destruction complete after 43s
azurerm_network_interface.nic: Destroying... [id=/subscriptions/[subscription id]/resourceGroups/example-rg/providers/Microsoft.Network/networkInterfaces/example-nic]
azurerm_network_interface.nic: Still destroying... [id=/subscriptions/[subscription id]....Network/networkInterfaces/example-nic, 00m10s elapsed]
azurerm_network_interface.nic: Destruction complete after 11s
azurerm_public_ip.public_ip: Destroying... [id=/subscriptions/[subscription id]/resourceGroups/example-rg/providers/Microsoft.Network/publicIPAddresses/example-pip]
azurerm_subnet.subnet: Destroying... [id=/subscriptions/[subscription id]/resourceGroups/example-rg/providers/Microsoft.Network/virtualNetworks/example-vnet/subnets/example-subnet]
azurerm_public_ip.public_ip: Still destroying... [id=/subscriptions/[subscription id]....Network/publicIPAddresses/example-pip, 00m10s elapsed]
azurerm_subnet.subnet: Still destroying... [id=/subscriptions/[subscription id]...ks/example-vnet/subnets/example-subnet, 00m10s elapsed]
azurerm_subnet.subnet: Destruction complete after 10s
azurerm_virtual_network.vnet: Destroying... [id=/subscriptions/[subscription id]/resourceGroups/example-rg/providers/Microsoft.Network/virtualNetworks/example-vnet]
azurerm_public_ip.public_ip: Destruction complete after 11s
azurerm_virtual_network.vnet: Still destroying... [id=/subscriptions/[subscription id]...t.Network/virtualNetworks/example-vnet, 00m10s elapsed]
azurerm_virtual_network.vnet: Destruction complete after 11s
azurerm_resource_group.rg: Destroying... [id=/subscriptions/[subscription id]/resourceGroups/example-rg]
azurerm_resource_group.rg: Still destroying... [id=/subscriptions/[subscription id]/resourceGroups/example-rg, 00m10s elapsed]
azurerm_resource_group.rg: Destruction complete after 16s

Destroy complete! Resources: 6 destroyed.

Azure portal上でもリソースが削除されていることが確認できました。