I have some templates using null-resource and executing remote-exec commands via ssh or winrm. When the target execution is complete there are files left on the target systems
e.g.
c:\temp\terraform_nnnnnnnn.cmd
on windows
or
/tmp/terraform_nnnnnnnn.sh
on linux.
These are never cleaned up even if I run a destroy/delete on the template instance.
Is there a way to clean these up after the remote-exec has completed without errors?
Here is a sample template that outlines what we are doing …
resource "null_resource" "TEST" {
connection {
type = "winrm"
user = "Administrator"
password = "passw0rd"
host = "1.2.3.4"
}
provisioner "file" {
source = "script.ps1"
destination = "C:\\temp\\script.ps1"
}
provisioner "remote-exec" {
inline = [
"powershell.exe -File C:\\temp\\script.ps1"
]
}
}