I am trying to use the following within my terraform execution:
resource "azurerm_virtual_machine_extension" "vmex" {
name = "myVM"
location = "eastus"
resource_group_name = "${azurerm_resource_group.rg.name}"
virtual_machine_name = "${azurerm_virtual_machine.vm.name}"
publisher = "Microsoft.Compute"
type = "CustomScriptExtension"
type_handler_version = "1.9"
settings = <<SETTINGS
{
"fileUris": [
"https://example.com/scripts/test.ps1"
],
"commandToExecute": "powershell -ExecutionPolicy Unrestricted -File 'test.ps1'"
}
SETTINGS
}
When this executes, I get the following output:
Error: Error applying plan:
1 error(s) occurred:
azurerm_virtual_machine_extension.vmex: 1 error(s) occurred:
azurerm_virtual_machine_extension.vmex: Long running operation terminated with status 'Failed': Code="VMExtensionProvisioningError" Message="VM has reported a failure when processing extension 'myVM'. Error message: \"Finished executing command\"."
Terraform does not automatically rollback in the face of errors. Instead, your Terraform state file has been partially updated with any resources that successfully completed. Please address the error above and apply again to incrementally change your infrastructure.
When I RDP into the VM, I can see that the file is correctly downloaded into the location that it is meant to be, however, it seems as though the commandToExecute
is never executed.
If I run the script directly from the downloads folder, it successfully completes.
Can anyone offer any suggestions as to what to try to do to resolve this?
NOTE: I have tried various combinations of trying to reference the file, but all of them seem to have the same result.
UPDATE: After checking the logs as suggested in the comments, the error when trying to run this snippet was:
"message": "Processing -File ''test.ps1'' failed because the file does not have a '.ps1' extension. Specify a valid Windows PowerShell script file name, and then try again."