- Run PowerShell from Terraform the first time only
- Run PowerShell from Terraform every time
- Run PowerShell from Terraform on a trigger
Run PowerShell from Terraform the first time only
We can then run terraform init and terraform apply and we see the output below and we can see Terraform ran the PowerShell script (no, you don't need to run terraform plan).
Run PowerShell from Terraform every time
As for the Terraform configuration, we're now adding a trigger which causes Terraform to run each time the trigger value changes. To do this, we're assigning a new UUID each time:
Terraform now runs the PowerShell script every time it runs.
Run PowerShell from Terraform on a defined trigger
Again, our PowerShell script is the same as before in the helpers folder.
To demonstrate this, we can add a variable TriggerValue and specify this in a variables.tf file. Terraform will expect us to pass this variable on the command line or via a TFVARS file.
Our Terraform configuration now needs to look like this. See that the trigger option is set to our TriggerValue variable.
When we run our configuration the first time using terraform apply, we need to specify the value for the variable (terraform apply -var TriggerValue=100) and we see that the script runs: