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

Parameter 'osProfile' is not allowed. #3247

Closed dontreboot closed 5 years ago

dontreboot commented 5 years ago

I have problems with creating a virtual machine with a vsrx image from Azure Marketplace. The image works fine if I create an VM using the Azure portal; however, for Terraform, if I set storage_os_disk create_option, I got error "Changing property 'osDisk.name' is not allowed".

If I create a managed_disk with the image first, then I attach it and I can't set os_profile because I was getting this error:

* azurerm_virtual_machine.vsrx: compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="InvalidParameter" Message="Parameter 'osProfile' is not allowed." Target="osProfile"

I want to be able to add a custom user and ssh_key for the virtual machine; hence, I wanted to update os_profile parameters. Anyone has ideas?

resource "azurerm_managed_disk" "vsrx" {
  name                 = "${format("%s-FW01", var.site_code)}"
  location             = "${var.location}"
  resource_group_name  = "${var.resource_group_name}"
  storage_account_type = "Premium_LRS"
  create_option        = "FromImage"
  disk_size_gb         = "16"
  os_type              = "Linux"
  image_reference_id   = "/Subscriptions/9e9ac3bf-b308-43ec-9fb4-02556557afea/Providers/Microsoft.Compute/Locations/WestIndia/Publishers/juniper-networks/ArtifactTypes/VMImage/Offers/vsrx-next-generation-firewall/Skus/vsrx-byol-azure-image/Versions/1.0.4"
}

resource "azurerm_virtual_machine" "vsrx" {
  name                = "${format("%s-FW01", var.site_code)}"
  location            = "${var.location}"
  resource_group_name = "${var.resource_group_name}"

  vm_size = "${var.vm_size}"

  network_interface_ids = ["${azurerm_network_interface.admin.id}", "${azurerm_network_interface.vlan8.id}", "${azurerm_network_interface.vlan9.id}", "${azurerm_network_interface.vlan12.id}"]

  primary_network_interface_id  = "${azurerm_network_interface.admin.id}"
  delete_os_disk_on_termination = true

  plan {
    name      = "vsrx-byol-azure-image"
    publisher = "juniper-networks"
    product   = "vsrx-next-generation-firewall"
  }

  storage_os_disk {
    name            = "${format("%s-FW02", var.site_code)}"
    create_option   = "Attach"
    os_type         = "Linux"
    managed_disk_id = "${azurerm_managed_disk.vsrx.id}"
  }

  os_profile {
    computer_name  = "${format("%s-FW02", var.site_code)}"
    admin_username = "${var.admin_username}"
  }
  os_profile_linux_config {
    disable_password_authentication = true

    ssh_keys {
      path     = "${format("/home/%s/.ssh/authorized_keys", var.admin_username)}"
      key_data = "xxxxx"
    }
  }
}
tombuildsstuff commented 5 years ago

hi @dontreboot

Thanks for opening this issue.

Unfortunately Azure doesn't allow attaching an existing OS Disk to a Virtual Machine created from a Plan - however you can instead set the create_option attribute to FromImage as shown in this example. Would you be able to take a look and see if that works for you?

As mentioned in the issue template unfortunately we're unable to answer Azure specific configuration questions, instead you're likely to get a better/faster response using one of the community resources instead - as such I'm going to close this issue for the moment.

Thanks!

ghost commented 5 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!