hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.51k stars 4.59k forks source link

azurerm_managed_disk update fails with a vmss virtual machine #26651

Open splunker1337 opened 1 month ago

splunker1337 commented 1 month ago

Is there an existing issue for this?

Community Note

Terraform Version

1.5.7

AzureRM Provider Version

3.0.0

Affected Resource(s)/Data Source(s)

azurerm_managed_disk

Terraform Configuration Files

module "naming" {
  source  = "Azure/naming/azurerm"
  version = "0.4.1"
  prefix  = [var.stack]
  suffix  = [var.si_name, var.env]
}

# Resource group definition
resource "azurerm_resource_group" "instance" {
  name     = module.naming.resource_group.name
  location = var.location
}

resource "azurerm_subnet" "instance" {
  name                 = "${var.stack}-subnet"
  resource_group_name  = var.network_resource_group
  virtual_network_name = "${var.virtual_network_name}-vnet"
  address_prefixes     = ["10.0.148.0/25"]
}

data "azurerm_client_config" "current" {}

locals {
  disk_tag_key   = "Name"
  disk_tag_value = "${var.stack}-foo-${var.env}"

  disk_tags = {
    tostring(local.disk_tag_key) = local.disk_tag_value
  }

  instance_registration_tags = {
    "SkipDNSRegistration" = "true"
  }
}

# Virtual Machine resource
resource "azurerm_linux_virtual_machine_scale_set" "instance" {
  name                       = module.naming.linux_virtual_machine_scale_set.name_unique
  resource_group_name        = azurerm_resource_group.instance.name
  location                   = var.location
  sku                        = "Standard_F8s_v2"
  instances                  = 1
  admin_username             = "ubuntu"
  source_image_id            = var.image_id
  user_data                  = base64encode(module.userdata.configuration)
  encryption_at_host_enabled = true
  overprovision              = false

  tags = merge(local.instance_tags, local.instance_registration_tags, var.tags)

  admin_ssh_key {
    public_key = file(var.ssh_public_key)
    username   = var.admin_username
  }

  os_disk {
    caching              = var.os_disk_caching
    storage_account_type = var.os_disk_storage_account_type
    disk_size_gb         = var.os_disk_size_gb
  }

  network_interface {
    name    = var.network_name
    primary = true

    ip_configuration {
      name                                   = var.ip_config_name
      primary                                = true
      subnet_id                              = azurerm_subnet.instance.id
      load_balancer_backend_address_pool_ids = [azurerm_lb_backend_address_pool.instance.id]
    }
  }

  automatic_instance_repair {
    enabled = true
  }

  identity {
    type         = var.identity_type
    identity_ids = var.identity_ids
  }

}

resource "azurerm_monitor_autoscale_setting" "instance" {
  name                = module.naming.monitor_autoscale_setting.name
  resource_group_name = azurerm_resource_group.instance.name
  location            = azurerm_resource_group.instance.location
  target_resource_id  = azurerm_linux_virtual_machine_scale_set.instance.id
  enabled             = true

  profile {
    name = "Monitor profile"

    capacity {
      default = 1
      maximum = 1
      minimum = 1
    }
  }

  tags = var.tags
}

# Disk resource for VM
resource "azurerm_managed_disk" "instance" {
  name                   = module.naming.managed_disk.name_unique
  location               = var.location
  resource_group_name    = azurerm_resource_group.instance.name
  storage_account_type   = var.data_disk_storage_account_type
  create_option          = var.data_disk_method
  disk_size_gb           = var.data_disk_size_gb
  disk_encryption_set_id = var.disk_encryption_set_id

  tags = merge(local.disk_tags, var.tags)
}

Debug Output/Panic Output

# module.instance.azurerm_managed_disk.instance will be updated in-place
  ~ resource "azurerm_managed_disk" "instance" {
      ~ disk_size_gb                      = 600 -> 660
        id                                = "/subscriptions/12345678/resourceGroups/resourcegroup/providers/Microsoft.Compute/disks/disk-dev-ifo8"
        name                              = "disk-dev-ifo8"
        # (17 unchanged attributes hidden)
    }

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

Error: parsing VMID "/subscriptions/12345678/resourceGroups/resourcegroup/providers/Microsoft.Compute/virtualMachineScaleSets/vmss-dev-ifo8/virtualMachines/vmss-dev-ifo8_0" for disk attachment: parsing "/subscriptions/12345678/resourceGroups/resourcegroup/providers/Microsoft.Compute/virtualMachineScaleSets/vmss-dev-ifo8/virtualMachines/vmss-dev-ifo8_0": parsing segment "staticVirtualMachines": parsing the VirtualMachine ID: the segment at position 6 didn't match

Expected a VirtualMachine ID that matched:

> /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Compute/virtualMachines/virtualMachineValue

However this value was provided:

> /subscriptions/12345678/resourceGroups/resourcegroup/providers/Microsoft.Compute/virtualMachineScaleSets/vmss-dev-ifo8/virtualMachines/vmss-dev-ifo8_0

The parsed Resource ID was missing a value for the segment at position 6
(which should be the literal value "virtualMachines").

  with module.instance.azurerm_managed_disk.instance,
  on ../../modules/azure/instance/main.tf line 340, in resource "azurerm_managed_disk" "instance":
 340: resource "azurerm_managed_disk" "instance" {

Expected Behaviour

Disk size would increase and terraform apply would finish successfully

Actual Behaviour

Terraform apply fails, because it is expecting a virtual machine instead of a virtual machine scale set virtual machine

Steps to Reproduce

No response

Important Factoids

No response

References

No response

konglingning commented 1 month ago

Hi, I got this error as well:

2024-07-18T01:31:07.2401030Z │ Error: parsing VMID "/subscriptions/123abc/resourceGroups/test-env-aks-rg-ressources/providers/Microsoft.Compute/virtualMachineScaleSets/aks-minion-xxx-vmss/virtualMachines/aks-minion-xxx-vmss_2" for disk attachment: parsing "/subscriptions/123abc/resourceGroups/test-env-aks-rg-ressources/providers/Microsoft.Compute/virtualMachineScaleSets/aks-minion-12761558-vmss/virtualMachines/aks-minion-12761558-vmss_2": parsing segment "staticVirtualMachines": parsing the VirtualMachine ID: the segment at position 6 didn't match`
2024-07-18T01:31:07.2405934Z │ Expected a VirtualMachine ID that matched: 
2024-07-18T01:31:07.2408454Z │ > /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Compute/virtualMachines/virtualMachineValue
2024-07-18T01:31:07.2432393Z │ However this value was provided:
2024-07-18T01:31:07.2434483Z │ > /subscriptions/123abc/resourceGroups/test-env-aks-rg-ressources/providers/Microsoft.Compute/virtualMachineScaleSets/aks-minion-xxx-vmss/virtualMachines/aks-minion-xxx-vmss_2
2024-07-18T01:31:07.2436612Z │ The parsed Resource ID was missing a value for the segment at position 6
2024-07-18T01:31:07.2437517Z │ (which should be the literal value "virtualMachines").
Selvas666 commented 2 weeks ago

I get the same error when trying to increase the size of a disk used as a statically provisioned volume in AKS.

terraform version = 1.6.3 hashicorp/azurerm version = 3.93.0