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.6k stars 4.64k forks source link

creating Linux Virtual Machine Scale Set: compute.VirtualMachineScaleSetsClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="InvalidParameter" Message="Parameter 'osProfile' is not allowed." Target="osProfile" #17331

Open ziyi-bear opened 2 years ago

ziyi-bear commented 2 years ago

Is there an existing issue for this?

Community Note

I want to create the vm-scale set using my created image, but show this error message, my image was not general but specialized, how can i create throught terraform? Many thanks

Terraform has been successfully initialized!
Acquiring state lock. This may take a few moments...
azurerm_linux_virtual_machine_scale_set.backup_vmss: Creating...
╷
│ Error: creating Linux Virtual Machine Scale Set: (Name "xxxx-backup-vmss" / Resource Group "xxxx"): compute.VirtualMachineScaleSetsClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="InvalidParameter" Message="Parameter 'osProfile' is not allowed." Target="osProfile"
│ 
│   with azurerm_linux_virtual_machine_scale_set.backup_vmss,
│   on step01_linux_virtual_machine_scale_set.backup.tf line 10, in resource "azurerm_linux_virtual_machine_scale_set" "backup_vmss":
│   10: resource "azurerm_linux_virtual_machine_scale_set" "backup_vmss" {
│ 
╵
Releasing state lock. This may take a few moments...

Terraform Version

1.1.9

AzureRM Provider Version

3.10.0

Affected Resource(s)/Data Source(s)

azurerm_linux_virtual_machine_scale_set

Terraform Configuration Files

## https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/shared_image_gallery
data "azurerm_shared_image_gallery" "shared_image_gallery" {
  name                = format("%s_shared_image_gallery", var.prefix)
  resource_group_name = data.azurerm_resource_group.target_rg.name
}

## https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/shared_image
data "azurerm_shared_image" "tcpass_shared_image_specialized" {
  name                = format("%s_shared_image_specialized", var.prefix)
  gallery_name        = data.azurerm_shared_image_gallery.shared_image_gallery.name
  resource_group_name = data.azurerm_resource_group.target_rg.name
}

## https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/shared_image_version
data "azurerm_shared_image_version" "tcpass_shared_image_version" {
  name                = var.image_version
  image_name          = data.azurerm_shared_image.tcpass_shared_image_specialized.name
  gallery_name        = data.azurerm_shared_image_gallery.shared_image_gallery.name
  resource_group_name = data.azurerm_resource_group.target_rg.name
}

## 
resource "azurerm_linux_virtual_machine_scale_set" "backup_vmss" {
  name                = format("%s-%s-vmss", var.prefix, var.backup_alias_name)
  resource_group_name = data.azurerm_resource_group.target_rg.name
  location            = var.backup_region
  sku                 = "Standard_DS1_v2"
  instances           = 3
  admin_username      = var.linux_admin_username
  admin_password      = var.linux_admin_password
  disable_password_authentication = false
  overprovision       = true

  source_image_id = data.azurerm_shared_image_version.tcpass_shared_image_version.id

  os_disk {
    storage_account_type = "Premium_LRS"
    caching              = "ReadWrite"
  }

  # Since these can change via auto-scaling outside of Terraform,
  # let's ignore any changes to the number of instances
  lifecycle {
    ignore_changes = [instances]
  }

  network_interface {
    name    = format("%s-%s-vmss-nic", var.prefix, var.backup_alias_name)
    primary = true

    ip_configuration {
      name      = "internal-vmss"
      primary   = true
      subnet_id = data.azurerm_subnet.backup_vm_scale_set_subnet.id
    }
  }
}

Debug Output/Panic Output

│ Error: creating Linux Virtual Machine Scale Set: (Name "xxxx-backup-vmss" / Resource Group "xxxx"): compute.VirtualMachineScaleSetsClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="InvalidParameter" Message="Parameter 'osProfile' is not allowed." Target="osProfile"
│ 
│   with azurerm_linux_virtual_machine_scale_set.backup_vmss,
│   on step01_linux_virtual_machine_scale_set.backup.tf line 10, in resource "azurerm_linux_virtual_machine_scale_set" "backup_vmss":
│   10: resource "azurerm_linux_virtual_machine_scale_set" "backup_vmss" {
│ 
╵
Releasing state lock. This may take a few moments...

Expected Behaviour

success create vmss

previous terraform plan is success, but stuck on terraform apply

Terraform has been successfully initialized!
Acquiring state lock. This may take a few moments...
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_scale_set.backup_vmss will be created
  + resource "azurerm_linux_virtual_machine_scale_set" "backup_vmss" {
      + admin_password                                    = (sensitive value)
      + admin_username                                    = "azureadmin"
      + computer_name_prefix                              = (known after apply)
      + disable_password_authentication                   = false
      + do_not_run_extensions_on_overprovisioned_machines = false
      + extensions_time_budget                            = "PT1H30M"
      + id                                                = (known after apply)
      + instances                                         = 3
      + location                                          = "koreacentral"
      + max_bid_price                                     = -1
      + name                                              = "funtaichung-backup-vmss"
      + overprovision                                     = true
      + platform_fault_domain_count                       = (known after apply)
      + priority                                          = "Regular"
      + provision_vm_agent                                = true
      + resource_group_name                               = "funtaichung"
      + scale_in_policy                                   = "Default"
      + single_placement_group                            = true
      + sku                                               = "Standard_DS1_v2"
      + source_image_id                                   = "/subscriptions/6c087038-2fd3-43c1-aa4e-6b[54](https://gitlab.com/b30f-systex/azure-terraform/tcpass-vmss-app/-/jobs/2623043565#L54)c0955808/resourceGroups/funtaichung/providers/Microsoft.Compute/galleries/funtaichung_shared_image_gallery/images/funtaichung_shared_image_specialized/versions/0.0.1"
      + unique_id                                         = (known after apply)
      + upgrade_mode                                      = "Manual"
      + zone_balance                                      = false
      + automatic_instance_repair {
          + enabled      = (known after apply)
          + grace_period = (known after apply)
        }
      + extension {
          + auto_upgrade_minor_version = (known after apply)
          + automatic_upgrade_enabled  = (known after apply)
          + force_update_tag           = (known after apply)
          + name                       = (known after apply)
          + protected_settings         = (sensitive value)
          + provision_after_extensions = (known after apply)
          + publisher                  = (known after apply)
          + settings                   = (known after apply)
          + type                       = (known after apply)
          + type_handler_version       = (known after apply)
        }
      + network_interface {
          + enable_accelerated_networking = false
          + enable_ip_forwarding          = false
          + name                          = "funtaichung-backup-vmss-nic"
          + primary                       = true
          + ip_configuration {
              + name      = "internal-vmss"
              + primary   = true
              + subnet_id = "/subscriptions/6c087038-2fd3-43c1-aa4e-6b54c09[55](https://gitlab.com/b30f-systex/azure-terraform/tcpass-vmss-app/-/jobs/2623043565#L55)808/resourceGroups/funtaichung/providers/Microsoft.Network/virtualNetworks/funtaichung-backup-vNet/subnets/funtaichung-backup-vm-scale-set-subnet"
              + version   = "IPv4"
            }
        }
      + os_disk {
          + caching                   = "ReadWrite"
          + disk_size_gb              = (known after apply)
          + storage_account_type      = "Premium_LRS"
          + write_accelerator_enabled = false
        }
      + terminate_notification {
          + enabled = (known after apply)
          + timeout = (known after apply)
        }
      + termination_notification {
          + enabled = (known after apply)
          + timeout = (known after apply)
        }
    }
Plan: 1 to add, 0 to change, 0 to destroy.

Actual Behaviour

show error, and stop deploy

Steps to Reproduce

terraform apply

Important Factoids

No response

References

No response

lingclound commented 2 years ago

this issue seems last more than 2 years, no final solution until now, is there any workaround , thanks in advance

magswildor commented 1 year ago

Hello, any update on this issue? From my research, it seems to be related to specialised image being created with a username and password. From https://learn.microsoft.com/en-us/azure/virtual-machines/troubleshooting-shared-images#creating-or-updating-a-vm-or-scale-sets-from-an-image-version

image

azurerm_linux_virtual_machine_scale_set will not accept null, empty string value or the same username and password used when specialised image was created

RobertMyles commented 1 year ago

A fix for this would be a big help, thanks!

nisargtk commented 7 months ago

Also facing the same issue. Any work around ?

quangvu-august commented 4 months ago

I had the same issue. Are there any solutions for that, please?