Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terraform - Is there any way to capture the shell script output (from remote vm) and store it in Terraform output (state file on local/consul)?

Tags:

terraform

I am creating cloud infrastructure using Terraform (e.g. AWS EC2 VM) and after VM creation, I am running a shell script on remote VM using provisioner(remote-exec).

Is there any way to capture the shell script output (from remote vm) and store it in Terraform output (state file on local/consul)?

I already tried Terraform's 'External Data Source' but I guess it works only with local scripts (not remote vm scripts). Please correct me in case I am wrong.

Thanks

like image 677
Akash Agrawal Avatar asked Oct 23 '25 05:10

Akash Agrawal


1 Answers

Creation-time or Destroy-time provisioners in Terraform only apply once during the resource creation/destroy, not during updating or any other lifecycle. For that reason the output of the provisioners won't be available in the terraform state.

Reference : https://www.terraform.io/docs/provisioners/index.html

like image 178
Koe Avatar answered Oct 26 '25 00:10

Koe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!