3
votes

I am trying to use custom_data field of resource azurerm_virtual_machine, but getting caught up into this error. Any idea what I am missing or is that a wrong usage?

resource "azurerm_virtual_machine" "csrVM" {
  name                  = "csr-terraform-poc"
  location              = "${var.location}"
  resource_group_name   = "${azurerm_resource_group.terraformRG.name}"
  network_interface_ids = ["${azurerm_network_interface.terraformNic1.id}",
                           "${azurerm_network_interface.terraformNic2.id}"]
  primary_network_interface_id = "${azurerm_network_interface.terraformNic1.id}"
  vm_size               = "Standard_DS1_v2"

  custom_data = "${file("customdata.txt")}"
  #custom_data = <<CUSTOMDATA
  #username testuser privilege 15 password testpass
  #enable password testpass
#CUSTOMDATA

~>terraform apply -var-file=azure.tfvars

Error: azurerm_virtual_machine.csrVM: : invalid or unknown key: custom_data

~>terraform -v Terraform v0.11.3 + provider.azurerm v1.1.1

1
I'm unable to find any links on how to pass scripts to this custom_data field. Can you send me any reference links.??vishal
as mentioned in answer. it is os_profile node. terraform.io/docs/providers/azurerm/r/…explorer

1 Answers

2
votes

I've never used terraform, but looking at the resource definition you need to create a os_profile node and place custom_data there.

os_profile supports the following:

computer_name - (Required) Specifies the name of the virtual machine.  
admin_username - (Required) Specifies the name of the administrator account.  
admin_password - (Required for Windows, Optional for Linux) Specifies the password of the administrator account.  
custom_data - (Optional) Specifies custom data to supply to the machine. On linux-based systems, this can be used as a cloud-init script. On other systems, this will be copied as a file on disk. Internally, Terraform will base64 encode this value before sending it to the API. The maximum length of the binary array is 65535 bytes.