July 26, 2020
terraform: execute powershell remotely
-
you could even use terraform as command line client to run scripts remotely (as an alternative to ssh).
-
copy script to target
-
execute on target
-
connect via winRM and a domain account
-
the greatest hassle: open up winrm, use ConfigureRemotingForAnsible.ps1 as starter.
resource "null_resource" "terraform_sample"{
triggers = {
last_windows_update = "2020-03-24.008"
}
connection {
type = "winrm"
user = " DOMAIN \\MServiceAdonis"
password = "***"
host = "xxxadonis4.DOMAIN.local"
timeout = "20s"
https = true (or false)
use_ntlm = true
insecure = true
}
provisioner "file" {
source = "D:/data/projects/terraform/local/tf-scripts/"
destination = "d:/tf-scripts"
}
provisioner "remote-exec" {
inline = [
"powershell -File d:/tf-scripts/info.ps1"
]
}
}
see also: