3
votes

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

2

2 Answers

1
votes

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

0
votes

https://github.com/matti/terraform-shell-resource module captures output from temporary files to triggers where they are stored in the state. The same pattern could maybe work for remote-exec too? Or, then just use local-exec to run command on the remote.