Hi Guys
I'm stuck trying to provision a crappy Windows Box in AWS using terraform.
Is there any way to set a variable
during the terraform apply process?
I have an instance with a local-exec provisioner which runs a script to get the password for a windows instance.
After the local-exec provisioner has completed, a remote-exec provisioner runs and I want the config for the remote-exec provisioner to use the windows password that was obtained by the local-exec provisioner.
I've tried the following:
In my
variables.tf file I have declared a variable with a default value of "" e.g:
variable "windows_password" {
default = ""
}
In my local-exec script, once I've got my windows password I have tried to export the value as an environment variable e.g:
export TF_VAR_ windows_password=something
Then in my config for my remote-exec provisioner I've got the following:
connection {
type = "winrm"
timeout = "10m"
password = "${var.windows_password}"
}
The problem is that the var.windows_password variable doesn't appear to have been set so I assume that the local-exec provisioner runs in a new shell and therefore the main terraform process doesn't have access to the variable I exported - this is a guess so correct me if I'm wrong.
Is there any way to achieve what I'm trying to achieve here and have a value calculated in my local-exec provisioner and then use that value in my remote-exec config?
Any help or advice would be greatly appreciated!
Thanks!