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.61k stars 4.65k forks source link

Terraform Azure Virtual Machine from Community images #25612

Open motorbreth opened 7 months ago

motorbreth commented 7 months ago

Is there an existing issue for this?

Community Note

Terraform Version

1.6.5

AzureRM Provider Version

3.98.0

Affected Resource(s)/Data Source(s)

azurerm_linux_virtual_machine

Terraform Configuration Files

resource "azurerm_network_interface" "VM_nic" {
  name                = "VM-nic"
  location            = azurerm_resource_group.servers.location
  resource_group_name = azurerm_resource_group.servers.name

  ip_configuration {
    name                          = "internal"
    subnet_id                     = azurerm_subnet.servers_subnet.id
    private_ip_address_allocation = "Dynamic"

resource "azurerm_linux_virtual_machine" "BackBox_vm" {
  name                            = "BackBox"
  computer_name                   = "BackBox"
  location                        = azurerm_resource_group.servers.location
  resource_group_name             = azurerm_resource_group.servers.name
  zone                            = "1"
  network_interface_ids           = [azurerm_network_interface.VM_nic.id]
  size                            = "Standard_D2s_v3"
  source_image_id                 = "/communityGalleries/BackBox-39ccaf4b-e81f-4250-a8f4-e32bc23a8312/images/BackBox"
  admin_username                  = "admin"
  admin_password                  = "Passw0rd"

  disable_password_authentication = false

  os_disk {
    name                 = "os-disk"
    caching              = "ReadWrite"
    storage_account_type = "Premium_LRS"
    disk_size_gb         = 128
  }
}

Debug Output/Panic Output

this image dosnt need a user and password set , when creating the vm in azure portal its not asking for a user and password , when running terraform it fails with missing user name or password

but when i set 
admin_username                  = "admin"
admin_password                  = "Passw0rd"
disable_password_authentication = false
it fails with 

Virtual Machine Name: "BackBox"): compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="InvalidParameter" Message="Parameter 'osProfile' is not allowed." Target="osProfile"

Expected Behaviour

create a vm from comunity image and add username and password later in the install process of the vm

Actual Behaviour

terraform plan works terraform apply fails with Virtual Machine Name: "BackBox"): compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="InvalidParameter" Message="Parameter 'osProfile' is not allowed." Target="osProfile"

Steps to Reproduce

resource "azurerm_network_interface" "VM_nic" {
  name                = "VM-nic"
  location            = azurerm_resource_group.servers.location
  resource_group_name = azurerm_resource_group.servers.name

  ip_configuration {
    name                          = "internal"
    subnet_id                     = azurerm_subnet.servers_subnet.id
    private_ip_address_allocation = "Dynamic"

resource "azurerm_linux_virtual_machine" "BackBox_vm" {
  name                            = "BackBox"
  computer_name                   = "BackBox"
  location                        = azurerm_resource_group.servers.location
  resource_group_name             = azurerm_resource_group.servers.name
  zone                            = "1"
  network_interface_ids           = [azurerm_network_interface.VM_nic.id]
  size                            = "Standard_D2s_v3"
  source_image_id                 = "/communityGalleries/BackBox-39ccaf4b-e81f-4250-a8f4-e32bc23a8312/images/BackBox"
  admin_username                  = "admin"
  admin_password                  = "Passw0rd"

  disable_password_authentication = false

  os_disk {
    name                 = "os-disk"
    caching              = "ReadWrite"
    storage_account_type = "Premium_LRS"
    disk_size_gb         = 128
  }
}

terraform apply

Important Factoids

No response

References

No response

ghost commented 5 months ago

any update ?