0

While we create Virtual machine scale set in azure , there is an option for passing the Custom data under Operating System like below enter image description here

How can i pass the script there using terraform , there is an option custom data which seems to be used for newly created machines from terraform, but the script is not getting stored there. How do i fill this with the script i have using terraform. Any help on this would be appreciated.

windowws
  • 373
  • 1
  • 8
  • 20
  • Are you suggesting you want to pass custom_data after provisioning? – Christian Pearce Sep 08 '20 at 11:25
  • i dont get you @ChristianPearce , can you please ask again – windowws Sep 08 '20 at 11:27
  • https://www.terraform.io/docs/providers/azurerm/r/virtual_machine.html#custom_data – Liam Sep 08 '20 at 12:16
  • Is your question suggesting the custom_data field is not working in terraform Be cause it is not showing up in the Custom Data field in the portal? can you post your example code? – Christian Pearce Sep 08 '20 at 13:46
  • 1
    no, actually, `custom data` field in the portal is saved for all the servers coming under the `vmss` , but the `custom data` using terraform is applying straight to the servers, instead of storing it here is what my question is. – windowws Sep 08 '20 at 14:23

1 Answers1

0

From the official document, the custom_data can only be passed to the Azure VM at provisioning time.

Custom data is only made available to the VM during first boot/initial setup, we call this 'provisioning'. Provisioning is the process where VM Create parameters (for example, hostname, username, password, certificates, custom data, keys etc.) are made available to the VM and a provisioning agent processes them, such as the Linux Agent and cloud-init.

The scripts are saved differed from the OS.

Windows

Custom data is placed in %SYSTEMDRIVE%\AzureData\CustomData.bin as a binary file, but it is not processed.

Linux

Custom data is passed to the VM via the ovf-env.xml file, which is copied to the /var/lib/waagent directory during provisioning. Newer versions of the Microsoft Azure Linux Agent will also copy the base64-encoded data to /var/lib/waagent/CustomData as well for convenience.

To upload custom_data from your local path to your Azure VM with terraform, you can use filebase64 Function.

For example, there is a test.sh script or cloud-init.txt file under the path where your main.tfor terraform.exe file exists.

 custom_data = filebase64("${path.module}/test.sh")

If you are looking for executing scripts after VMSS created, you could look at the custom extension and this sample.

Nancy
  • 26,865
  • 3
  • 18
  • 34
  • Thanks for the answer, but i think my question is not clear, in the `vmss` portal, there is a place to save the `customdata` for future servers that might come up during scaling, i wanted to save the `customdata` for those – windowws Sep 11 '20 at 01:59