1

Once the VMSS is up, I wanted to execute a shell script as part of the VMSS extension. This is what I tried but the script didn't execute.

My initial analysis is the script is not available to VMSS; in this case how to copy the script along with the tf build, I don't want to upload to blob storage and supply the path here. In case of VM I can achieve the same using file provisioner and remote-exec.

..................................
extension {
    name = "StartupScript"
    publisher = "Microsoft.OSTCExtensions"
    type = "CustomScriptForLinux"
    type_handler_version = "1.5"
    settings = <<-SETTINGS
    {
        "commandToExecute": "${var.startup_command}",
        #Script path from where my TF is running
        "script": "${base64encode("/bin/sh ./path_to_custom_scripts/my_script.sh script_param")}",
        "enableInternalDNSCheck": "false"
    }
    SETTINGS
  }
  ..................................

Didn't find much info in extension.log, any help is highly appreciable.

lambodar
  • 3,495
  • 5
  • 34
  • 58

1 Answers1

1

No, you cannot use file provisioner, at least I dont see a clear path forward with this approach, as this is not a single vm, but rather an amalgamation of vms.

As for your original question, no real way of doing that, if you want script extension, you have to upload it somewhere for nodes to pull it down.

You can try and use customData property. This allows you to store something on the vm\vmss node so its added to it at provision time.

4c74356b41
  • 69,186
  • 6
  • 100
  • 141
  • Thanks for the info. Will the customData approach be helpful during scale up and down? – lambodar Nov 30 '18 at 10:21
  • define "helpful"? it will be present on all the vmss nodes when they get created, no matter how. so it will be present during scale operations (wont help you on scale down) – 4c74356b41 Nov 30 '18 at 10:39
  • Really, a clear path forward would be for the vm scale set resource to accept a file provisioner such that the same file is placed on every node in the set. This would get round the customData which may not be available in an enterprise setting where the company eng team may have already effectively used it. – volvox Oct 04 '19 at 16:35
  • you can create a uservoice item for this. I usually use Powershell DSC to configure VMSS nodes on provision – 4c74356b41 Oct 04 '19 at 16:37