I had a task to create multiple Ubuntu Virtual Machines on Microsoft Azure using Terraform. Below is the code for the same. Requirement was VM information should be put into variable with type of map object (Multiple VMs will be created using it). Another requirement was there is already core infrastructure exists for Resource Group and Virtual Network vNet exist, use it as a data sources instead of creating new environment. For already created resources, create separate variable with combination of object and list type.
Below is the terraform script configuration to create VM on Azure. You can download it here Terraform_Create_Azure_Linux_Virtual_Machine.zip or it is also available on github.com.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
provider "azurerm" { features {} } variable "core_infra" { type = object({ resource_group_name = string virtual_network_name = string subnet = object({ name = string address_prefixes = list(string) //any }) }) default = { resource_group_name = "vcloud-lab.com" virtual_network_name = "vcloud_lab_global_vnet01" subnet = { name = "vcloud-test" address_prefixes = ["10.0.1.0/24"] } } } # variable "admin_password" { # type = string # sensitive = true # default = "Computer@123" # } variable "vm_map" { type = map(object({ name = string size = string admin_password = string })) default = { "vm01" = { name = "vm1" size = "Standard_B1s" admin_password = "Computer@123" } "vm02" = { name = "vm2" size = "Standard_B2s" admin_password = "Computer@1234" } } } data "azurerm_resource_group" "rg_info" { name = var.core_infra["resource_group_name"] } data "azurerm_virtual_network" "vnet_info" { name = var.core_infra["virtual_network_name"] resource_group_name = data.azurerm_resource_group.rg_info.name } resource "azurerm_subnet" "subnet" { name = var.core_infra["subnet"].name virtual_network_name = data.azurerm_virtual_network.vnet_info.name resource_group_name = data.azurerm_resource_group.rg_info.name address_prefixes = var.core_infra["subnet"].address_prefixes } resource "azurerm_network_interface" "nic" { for_each = var.vm_map name = "${each.key}-nic" location = data.azurerm_resource_group.rg_info.location resource_group_name = data.azurerm_resource_group.rg_info.name ip_configuration { name = "ipconfig" subnet_id = azurerm_subnet.subnet.id private_ip_address_allocation = "Dynamic" } } resource "azurerm_linux_virtual_machine" "vm" { for_each = var.vm_map name = each.value.name location = data.azurerm_resource_group.rg_info.location resource_group_name = data.azurerm_resource_group.rg_info.name size = each.value.size admin_username = "adminuser" admin_password = sensitive(each.value.admin_password) disable_password_authentication = false network_interface_ids = [azurerm_network_interface.nic[each.key].id] os_disk { caching = "ReadWrite" storage_account_type = "Standard_LRS" } source_image_reference { publisher = "Canonical" offer = "UbuntuServer" sku = "18.04-LTS" version = "latest" } custom_data = base64encode( <<EOF #!/bin/bash echo "Hello From ${each.value.name} !" EOF ) } |
Here is the screenshot of the Resource Group view after creating resources.
Above is the screenshot of deployed resources on Azure Cloud. You can run Terraform commands as usual. If you want to create tfvar file, you can use below var file Terraform template to store in filename terraform.tfvars, which will automatically load it when you run plan or apply without mentioned it and will use the values defined in the file.
If you have another name of .tfvars file, you can use command terraform init and terraform apply -var-file="custom.tfvars".
core_infra = { resource_group_name = "vcloud-lab.com" virtual_network_name = "vcloud_lab_global_vnet01" subnet = { name = "vcloud-test" address_prefixes = ["10.0.1.0/24"] } } vm_map = { "vm01" = { name = "vm1" size = "Standard_B1s" admin_password = "Computer@123" } "vm02" = { name = "vm2" size = "Standard_B2s" admin_password = "Computer@1234" } }
If you are providing variables directly in the apply command, compress/compact the text and provide it something like below.
terraform apply -var 'vm_map={"vm01"={"name"="vm1", "size"="Standard_B1s", "admin_password"="Computer@123"}, "vm02"={"name"="vm2", "size"="Standard_B2s", "admin_password"="Computer@1234"}}'
Below is the apply and destroy output of the configuration on Azure.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 |
terraform apply --auto-approve data.azurerm_resource_group.rg_info: Reading... data.azurerm_resource_group.rg_info: Read complete after 1s [id=/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com] data.azurerm_virtual_network.vnet_info: Reading... data.azurerm_virtual_network.vnet_info: Read complete after 1s [id=/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com/providers/Microsoft.Network/virtualNetworks/vcloud_lab_global_vnet01] 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["vm01"] will be created + resource "azurerm_linux_virtual_machine" "vm" { + admin_password = (sensitive value) + admin_username = "adminuser" + allow_extension_operations = true + bypass_platform_safety_checks_on_user_schedule_enabled = false + computer_name = (known after apply) + custom_data = (sensitive value) + disable_password_authentication = false + disk_controller_type = (known after apply) + extensions_time_budget = "PT1H30M" + id = (known after apply) + location = "eastus" + max_bid_price = -1 + name = "vm1" + 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 = "vcloud-lab.com" + size = "Standard_B1s" + virtual_machine_id = (known after apply) + vm_agent_platform_updates_enabled = false + os_disk { + caching = "ReadWrite" + disk_size_gb = (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_linux_virtual_machine.vm["vm02"] will be created + resource "azurerm_linux_virtual_machine" "vm" { + admin_password = (sensitive value) + admin_username = "adminuser" + allow_extension_operations = true + bypass_platform_safety_checks_on_user_schedule_enabled = false + computer_name = (known after apply) + custom_data = (sensitive value) + disable_password_authentication = false + disk_controller_type = (known after apply) + extensions_time_budget = "PT1H30M" + id = (known after apply) + location = "eastus" + max_bid_price = -1 + name = "vm2" + 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 = "vcloud-lab.com" + size = "Standard_B2s" + virtual_machine_id = (known after apply) + vm_agent_platform_updates_enabled = false + os_disk { + caching = "ReadWrite" + disk_size_gb = (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["vm01"] will be created + resource "azurerm_network_interface" "nic" { + accelerated_networking_enabled = (known after apply) + applied_dns_servers = (known after apply) + dns_servers = (known after apply) + enable_accelerated_networking = (known after apply) + enable_ip_forwarding = (known after apply) + id = (known after apply) + internal_domain_name_suffix = (known after apply) + ip_forwarding_enabled = (known after apply) + location = "eastus" + mac_address = (known after apply) + name = "vm01-nic" + private_ip_address = (known after apply) + private_ip_addresses = (known after apply) + resource_group_name = "vcloud-lab.com" + virtual_machine_id = (known after apply) + ip_configuration { + gateway_load_balancer_frontend_ip_configuration_id = (known after apply) + name = "ipconfig" + primary = (known after apply) + private_ip_address = (known after apply) + private_ip_address_allocation = "Dynamic" + private_ip_address_version = "IPv4" + subnet_id = (known after apply) } } # azurerm_network_interface.nic["vm02"] will be created + resource "azurerm_network_interface" "nic" { + accelerated_networking_enabled = (known after apply) + applied_dns_servers = (known after apply) + dns_servers = (known after apply) + enable_accelerated_networking = (known after apply) + enable_ip_forwarding = (known after apply) + id = (known after apply) + internal_domain_name_suffix = (known after apply) + ip_forwarding_enabled = (known after apply) + location = "eastus" + mac_address = (known after apply) + name = "vm02-nic" + private_ip_address = (known after apply) + private_ip_addresses = (known after apply) + resource_group_name = "vcloud-lab.com" + virtual_machine_id = (known after apply) + ip_configuration { + gateway_load_balancer_frontend_ip_configuration_id = (known after apply) + name = "ipconfig" + primary = (known after apply) + private_ip_address = (known after apply) + private_ip_address_allocation = "Dynamic" + private_ip_address_version = "IPv4" + subnet_id = (known after apply) } } # azurerm_subnet.subnet will be created + resource "azurerm_subnet" "subnet" { + address_prefixes = [ + "10.0.1.0/24", ] + default_outbound_access_enabled = true + enforce_private_link_endpoint_network_policies = (known after apply) + enforce_private_link_service_network_policies = (known after apply) + id = (known after apply) + name = "vcloud-test" + private_endpoint_network_policies = (known after apply) + private_endpoint_network_policies_enabled = (known after apply) + private_link_service_network_policies_enabled = (known after apply) + resource_group_name = "vcloud-lab.com" + virtual_network_name = "vcloud_lab_global_vnet01" } Plan: 5 to add, 0 to change, 0 to destroy. azurerm_subnet.subnet: Creating... azurerm_subnet.subnet: Creation complete after 7s [id=/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com/providers/Microsoft.Network/virtualNetworks/vcloud_lab_global_vnet01/subnets/vcloud-test] azurerm_network_interface.nic["vm01"]: Creating... azurerm_network_interface.nic["vm02"]: Creating... azurerm_network_interface.nic["vm01"]: Still creating... [10s elapsed] azurerm_network_interface.nic["vm02"]: Still creating... [10s elapsed] azurerm_network_interface.nic["vm02"]: Still creating... [20s elapsed] azurerm_network_interface.nic["vm01"]: Still creating... [20s elapsed] azurerm_network_interface.nic["vm01"]: Creation complete after 22s [id=/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com/providers/Microsoft.Network/networkInterfaces/vm01-nic] azurerm_network_interface.nic["vm02"]: Still creating... [30s elapsed] azurerm_network_interface.nic["vm02"]: Creation complete after 36s [id=/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com/providers/Microsoft.Network/networkInterfaces/vm02-nic] azurerm_linux_virtual_machine.vm["vm02"]: Creating... azurerm_linux_virtual_machine.vm["vm01"]: Creating... azurerm_linux_virtual_machine.vm["vm01"]: Still creating... [10s elapsed] azurerm_linux_virtual_machine.vm["vm02"]: Still creating... [10s elapsed] azurerm_linux_virtual_machine.vm["vm01"]: Still creating... [20s elapsed] azurerm_linux_virtual_machine.vm["vm02"]: Still creating... [20s elapsed] azurerm_linux_virtual_machine.vm["vm01"]: Creation complete after 22s [id=/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com/providers/Microsoft.Compute/virtualMachines/vm1] azurerm_linux_virtual_machine.vm["vm02"]: Creation complete after 22s [id=/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com/providers/Microsoft.Compute/virtualMachines/vm2] Apply complete! Resources: 5 added, 0 changed, 0 destroyed. Terraform destroy --auto-approve data.azurerm_resource_group.rg_info: Reading... data.azurerm_resource_group.rg_info: Read complete after 1s [id=/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com] data.azurerm_virtual_network.vnet_info: Reading... data.azurerm_virtual_network.vnet_info: Read complete after 1s [id=/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com/providers/Microsoft.Network/virtualNetworks/vcloud_lab_global_vnet01] azurerm_subnet.subnet: Refreshing state... [id=/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com/providers/Microsoft.Network/virtualNetworks/vcloud_lab_global_vnet01/subnets/vcloud-test] azurerm_network_interface.nic["vm01"]: Refreshing state... [id=/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com/providers/Microsoft.Network/networkInterfaces/vm01-nic] azurerm_network_interface.nic["vm02"]: Refreshing state... [id=/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com/providers/Microsoft.Network/networkInterfaces/vm02-nic] azurerm_linux_virtual_machine.vm["vm02"]: Refreshing state... [id=/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com/providers/Microsoft.Compute/virtualMachines/vm2] azurerm_linux_virtual_machine.vm["vm01"]: Refreshing state... [id=/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com/providers/Microsoft.Compute/virtualMachines/vm1] 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["vm01"] will be destroyed - resource "azurerm_linux_virtual_machine" "vm" { - admin_password = (sensitive value) -> null - admin_username = "adminuser" -> null - allow_extension_operations = true -> null - bypass_platform_safety_checks_on_user_schedule_enabled = false -> null - computer_name = "vm1" -> null - custom_data = (sensitive value) -> null - disable_password_authentication = false -> null - encryption_at_host_enabled = false -> null - extensions_time_budget = "PT1H30M" -> null - id = "/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com/providers/Microsoft.Compute/virtualMachines/vm1" -> null - location = "eastus" -> null - max_bid_price = -1 -> null - name = "vm1" -> null - network_interface_ids = [ - "/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com/providers/Microsoft.Network/networkInterfaces/vm01-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_addresses = [] -> null - resource_group_name = "vcloud-lab.com" -> null - secure_boot_enabled = false -> null - size = "Standard_B1s" -> null - tags = {} -> null - virtual_machine_id = "2c6a9802-fdb6-4180-a49e-75f90a3433bd" -> null - vm_agent_platform_updates_enabled = false -> null - vtpm_enabled = false -> null # (15 unchanged attributes hidden) - os_disk { - caching = "ReadWrite" -> null - disk_size_gb = 30 -> null - name = "vm1_disk1_9b7fec674e694a119ec6a5fb05bcfdfa" -> 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_linux_virtual_machine.vm["vm02"] will be destroyed - resource "azurerm_linux_virtual_machine" "vm" { - admin_password = (sensitive value) -> null - admin_username = "adminuser" -> null - allow_extension_operations = true -> null - bypass_platform_safety_checks_on_user_schedule_enabled = false -> null - computer_name = "vm2" -> null - custom_data = (sensitive value) -> null - disable_password_authentication = false -> null - encryption_at_host_enabled = false -> null - extensions_time_budget = "PT1H30M" -> null - id = "/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com/providers/Microsoft.Compute/virtualMachines/vm2" -> null - location = "eastus" -> null - max_bid_price = -1 -> null - name = "vm2" -> null - network_interface_ids = [ - "/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com/providers/Microsoft.Network/networkInterfaces/vm02-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.5" -> null - private_ip_addresses = [ - "10.0.1.5", ] -> null - provision_vm_agent = true -> null - public_ip_addresses = [] -> null - resource_group_name = "vcloud-lab.com" -> null - secure_boot_enabled = false -> null - size = "Standard_B2s" -> null - tags = {} -> null - virtual_machine_id = "04914f7b-873a-46d6-920e-050da450ce4c" -> null - vm_agent_platform_updates_enabled = false -> null - vtpm_enabled = false -> null # (15 unchanged attributes hidden) - os_disk { - caching = "ReadWrite" -> null - disk_size_gb = 30 -> null - name = "vm2_disk1_80f23380d52d40d38401447a7b8f025a" -> 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["vm01"] will be destroyed - resource "azurerm_network_interface" "nic" { - accelerated_networking_enabled = false -> null - applied_dns_servers = [] -> null - dns_servers = [] -> null - enable_accelerated_networking = false -> null - enable_ip_forwarding = false -> null - id = "/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com/providers/Microsoft.Network/networkInterfaces/vm01-nic" -> null - internal_domain_name_suffix = "o4kbtmz1jjau3dzjfagdkcfvnd.bx.internal.cloudapp.net" -> null - ip_forwarding_enabled = false -> null - location = "eastus" -> null - mac_address = "00-22-48-2E-B9-42" -> null - name = "vm01-nic" -> null - private_ip_address = "10.0.1.4" -> null - private_ip_addresses = [ - "10.0.1.4", ] -> null - resource_group_name = "vcloud-lab.com" -> null - tags = {} -> null - virtual_machine_id = "/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com/providers/Microsoft.Compute/virtualMachines/vm1" -> null # (4 unchanged attributes hidden) - ip_configuration { - name = "ipconfig" -> null - primary = true -> null - private_ip_address = "10.0.1.4" -> null - private_ip_address_allocation = "Dynamic" -> null - private_ip_address_version = "IPv4" -> null - subnet_id = "/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com/providers/Microsoft.Network/virtualNetworks/vcloud_lab_global_vnet01/subnets/vcloud-test" -> null # (2 unchanged attributes hidden) } } # azurerm_network_interface.nic["vm02"] will be destroyed - resource "azurerm_network_interface" "nic" { - accelerated_networking_enabled = false -> null - applied_dns_servers = [] -> null - dns_servers = [] -> null - enable_accelerated_networking = false -> null - enable_ip_forwarding = false -> null - id = "/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com/providers/Microsoft.Network/networkInterfaces/vm02-nic" -> null - internal_domain_name_suffix = "o4kbtmz1jjau3dzjfagdkcfvnd.bx.internal.cloudapp.net" -> null - ip_forwarding_enabled = false -> null - location = "eastus" -> null - mac_address = "7C-1E-52-00-D1-FE" -> null - name = "vm02-nic" -> null - private_ip_address = "10.0.1.5" -> null - private_ip_addresses = [ - "10.0.1.5", ] -> null - resource_group_name = "vcloud-lab.com" -> null - tags = {} -> null - virtual_machine_id = "/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com/providers/Microsoft.Compute/virtualMachines/vm2" -> null # (4 unchanged attributes hidden) - ip_configuration { - name = "ipconfig" -> null - primary = true -> null - private_ip_address = "10.0.1.5" -> null - private_ip_address_allocation = "Dynamic" -> null - private_ip_address_version = "IPv4" -> null - subnet_id = "/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com/providers/Microsoft.Network/virtualNetworks/vcloud_lab_global_vnet01/subnets/vcloud-test" -> null # (2 unchanged attributes 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 - enforce_private_link_endpoint_network_policies = false -> null - enforce_private_link_service_network_policies = false -> null - id = "/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com/providers/Microsoft.Network/virtualNetworks/vcloud_lab_global_vnet01/subnets/vcloud-test" -> null - name = "vcloud-test" -> null - private_endpoint_network_policies = "Enabled" -> null - private_endpoint_network_policies_enabled = true -> null - private_link_service_network_policies_enabled = true -> null - resource_group_name = "vcloud-lab.com" -> null - service_endpoint_policy_ids = [] -> null - service_endpoints = [] -> null - virtual_network_name = "vcloud_lab_global_vnet01" -> null } Plan: 0 to add, 0 to change, 5 to destroy. azurerm_linux_virtual_machine.vm["vm01"]: Destroying... [id=/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com/providers/Microsoft.Compute/virtualMachines/vm1] azurerm_linux_virtual_machine.vm["vm02"]: Destroying... [id=/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com/providers/Microsoft.Compute/virtualMachines/vm2] azurerm_linux_virtual_machine.vm["vm02"]: Still destroying... [id=/subscriptions/9e22fba3-00a9-447c-b954-.../Microsoft.Compute/virtualMachines/vm2, 10s elapsed] azurerm_linux_virtual_machine.vm["vm01"]: Still destroying... [id=/subscriptions/9e22fba3-00a9-447c-b954-.../Microsoft.Compute/virtualMachines/vm1, 10s elapsed] azurerm_linux_virtual_machine.vm["vm02"]: Still destroying... [id=/subscriptions/9e22fba3-00a9-447c-b954-.../Microsoft.Compute/virtualMachines/vm2, 20s elapsed] azurerm_linux_virtual_machine.vm["vm01"]: Still destroying... [id=/subscriptions/9e22fba3-00a9-447c-b954-.../Microsoft.Compute/virtualMachines/vm1, 20s elapsed] azurerm_linux_virtual_machine.vm["vm01"]: Still destroying... [id=/subscriptions/9e22fba3-00a9-447c-b954-.../Microsoft.Compute/virtualMachines/vm1, 30s elapsed] azurerm_linux_virtual_machine.vm["vm02"]: Still destroying... [id=/subscriptions/9e22fba3-00a9-447c-b954-.../Microsoft.Compute/virtualMachines/vm2, 30s elapsed] azurerm_linux_virtual_machine.vm["vm02"]: Still destroying... [id=/subscriptions/9e22fba3-00a9-447c-b954-.../Microsoft.Compute/virtualMachines/vm2, 40s elapsed] azurerm_linux_virtual_machine.vm["vm01"]: Still destroying... [id=/subscriptions/9e22fba3-00a9-447c-b954-.../Microsoft.Compute/virtualMachines/vm1, 40s elapsed] azurerm_linux_virtual_machine.vm["vm01"]: Still destroying... [id=/subscriptions/9e22fba3-00a9-447c-b954-.../Microsoft.Compute/virtualMachines/vm1, 50s elapsed] azurerm_linux_virtual_machine.vm["vm02"]: Still destroying... [id=/subscriptions/9e22fba3-00a9-447c-b954-.../Microsoft.Compute/virtualMachines/vm2, 50s elapsed] azurerm_linux_virtual_machine.vm["vm01"]: Destruction complete after 55s azurerm_linux_virtual_machine.vm["vm02"]: Destruction complete after 56s azurerm_network_interface.nic["vm02"]: Destroying... [id=/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com/providers/Microsoft.Network/networkInterfaces/vm02-nic] azurerm_network_interface.nic["vm01"]: Destroying... [id=/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com/providers/Microsoft.Network/networkInterfaces/vm01-nic] azurerm_network_interface.nic["vm01"]: Still destroying... [id=/subscriptions/9e22fba3-00a9-447c-b954-...oft.Network/networkInterfaces/vm01-nic, 10s elapsed] azurerm_network_interface.nic["vm02"]: Still destroying... [id=/subscriptions/9e22fba3-00a9-447c-b954-...oft.Network/networkInterfaces/vm02-nic, 10s elapsed] azurerm_network_interface.nic["vm02"]: Destruction complete after 15s azurerm_network_interface.nic["vm01"]: Still destroying... [id=/subscriptions/9e22fba3-00a9-447c-b954-...oft.Network/networkInterfaces/vm01-nic, 20s elapsed] azurerm_network_interface.nic["vm01"]: Destruction complete after 27s azurerm_subnet.subnet: Destroying... [id=/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/vcloud-lab.com/providers/Microsoft.Network/virtualNetworks/vcloud_lab_global_vnet01/subnets/vcloud-test] azurerm_subnet.subnet: Still destroying... [id=/subscriptions/9e22fba3-00a9-447c-b954-..._lab_global_vnet01/subnets/vcloud-test, 10s elapsed] azurerm_subnet.subnet: Destruction complete after 12s Destroy complete! Resources: 5 destroyed. |
Useful Articles
Terraform clone virtual machine template in VMware vSphere vCenter from CSV file
Terraform error retrieving storage account failure responding to request StatusCode 404 StorageAccountNotFound The storage account was not found
Terraform testing local variables and output csv file without resource Part 1
Terraform testing variable map object values without resource configuration part 2
Terraform foreach module output to show only required results
Terraform deploy create A Private DNS Record in Microsoft Azure from list of objects
Terraform clone virtual machine template in VMware vSphere vCenter Dynamic Content Part 2
Creating a Private Endpoint for Azure Storage Account with required sub services using Terraform
Terraform Azure Create Private Endpoint to existing Storage Account with Custom Private DNS zone record link
Using terraform to clone a virtual machine on VMware vSphere infrastructure
Terraform module clone VMware vSphere Linux and Windows virtual machine
Terraform VMware vSphere Virtual Machine customization clone failed on Windows
Terraform VMware vSphere Virtual Machine cloning Operating system not found
Creating a Private Endpoint for Azure Storage Account with Terraform example 3