0

I'm trying to figure out the proper way to pass terraform variable value to my Powershell script.

The script fails when I try to deploy it using Microsoft extension. Below is my terraform script:

resource "azurerm_virtual_machine_extension" "test" {
    name = "testt"
    virtual_machine_id = azurerm_virtual_machine.example.id
    publisher = "Microsoft.Compute"
    type = "CustomScriptExtension"
    type_handler_version = "1.9"            
    protected_settings = <<SETTINGS    
{    
"commandToExecute": "powershell -command \"[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('${base64encode(file("shell.ps1"))}')) | Out-File -filepath shell.ps1\" && powershell -ExecutionPolicy Unrestricted -File shell.ps1 -value1 ${var.value1} -value2 ${var.value2}"
    }    
SETTINGS    
}

Below is the Powershell script:

param(

  [string]$value1,
  [string]$value2
)

The error I am facing:

"message": "param : The term 'param' is not recognized as the name of a cmdlet, function, script file, or operable program. Check \r\nthe spelling of the name, or if a path was included, verify that the path is correct and try again.

1

1 Answer 1

0

Have you tried something like this?

param(
  [string]$value1 = ${var.value1},
  [string]$value2 = ${var.value2}
)
Sign up to request clarification or add additional context in comments.

1 Comment

Still facing the same error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.