1

Is there any way I can execute a command on remote machine with Terraform and have the result of that command show me by output? I can use provisioner(remote-exec) to install and run commands on remote machine but couldn't find a way to the result of the command show me by output.

Thank you for your time guys.

cloudops
  • 45
  • 7
  • `remote-exec` shows the stdout of the commands. So what is the actual issue? Do you have any example? – Marcin Nov 07 '21 at 21:50
  • @Marcin Teacher wants to see the password to be shown at the end of the operation with other outputs. This command sudo cat /var/lib/jenkins/secrets/initialAdminPassword will show the password from remote machine but how can I make it show it with outputs at the end of the Terraform apply operation? – cloudops Nov 07 '21 at 22:14

1 Answers1

1

You could do what you want with External Data Source. You would have to program the external data source to run the commands on the remote host and return what you want return for further processing in your TF code.

Other possibility is to have your remote-exec populate an external parameter store (e.g. SSM Parameter Store in AWS), and then once your remote-exec finishes, you would fetch the data from it using aws_ssm_parameter data source.

Marcin
  • 215,873
  • 14
  • 235
  • 294