0

I am trying to create azure cyclecloud server using terraform , my code is below note: remove the actual disk id ,vm id, public key etc

resource "azurerm_virtual_machine_data_disk_attachment" "res-0" {
  caching            = "None"
  create_option      = "FromImage"
  lun                = 0
  managed_disk_id    = "Disk_id"
  virtual_machine_id = "vm_id"
  depends_on = [
    azurerm_linux_virtual_machine.res-0,
  ]
}
resource "azurerm_linux_virtual_machine" "res-0" {
  admin_username        = "cyclecloud"
  location              = "westus2"
  name                  = "cc3"
  network_interface_ids = network_interfaces_id"
  resource_group_name   = "myrg"
  size                  = "Standard_DS1_v2"
  admin_ssh_key {
    public_key = "my_public_key"
    username   = "cyclecloud"
  }
  boot_diagnostics {
  }
  os_disk {
    caching              = "ReadWrite"
    storage_account_type = "Premium_LRS"
  }
  plan {
    name      = "cyclecloud-81"
    product   = "azure-cyclecloud"
    publisher = "azurecyclecloud"
  }
  source_image_reference {
    offer     = "azure-cyclecloud"
    publisher = "azurecyclecloud"
    sku       = "cyclecloud-81"
    version   = "latest"
  }
}

while running : terraform apply ,getting the below error:

 Error: expected create_option to be one of [Attach Empty], got FromImage

   with azurerm_virtual_machine_data_disk_attachment.res-0,
   on main.tf line 3, in resource "azurerm_virtual_machine_data_disk_attachment" "res-0":
    3:   create_option      = "FromImage"

Please assist

note i am using the below provider:

terraform {
  backend "local" {}
  required_providers {
    azurerm = {
      source = "hashicorp/azurerm"
      version = "3.31.0"
    }
  }
}

provider "azurerm" {
  features {}
}
isb
  • 53
  • 3

1 Answers1

0

The error clearly says that you are passing an unsupported value to the create_option attribute of resource azurerm_virtual_machine_data_disk_attachment. The possible values are Empty or Attach.

resource "azurerm_virtual_machine_data_disk_attachment" "res-0" {
  caching            = "None"
  create_option      = "Empty" ## or ## "Attach" # <- Choose any of these values. 
  lun                = 0
  managed_disk_id    = "Disk_id"
  virtual_machine_id = "vm_id"
  depends_on = [
    azurerm_linux_virtual_machine.res-0,
  ]
}

Refer to attribute description:

create_option - (Optional) The Create Option of the Data Disk, such as Empty or Attach. Defaults to Attach. Changing this forces a new resource to be created.

Official Documentation: https://registry.terraform.io/providers/hashicorp/azurerm/3.31.0/docs/resources/virtual_machine_data_disk_attachment#create_option

After this may be network_interface_ids = network_interfaces_id" this might result in an error if no real network_interface_ids are provided as the attribute values.

Refer to official hashicorp example : https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_virtual_machine

Not Sure but if the goal is to attach an additional data disk to the machine then azurerm_managed_disk resource is also required not only just attachment and there you can use create_option = FromImage attribute value.

create_option for the azurerm_managed_disk : https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/managed_disk#create_option

ishuar
  • 1,193
  • 1
  • 3
  • 6