TA-002-P · Question #340
As a member of the operations team, you need to run a script on a virtual machine created by Terraform. Which provisioned is best to use in your Terraform code?
The correct answer is D. remote-exec. To execute a script directly on a virtual machine managed by Terraform, the remote-exec provisioner is the most appropriate choice. This provisioner allows Terraform to connect to a remote resource using SSH or WinRM and run commands or scripts.
Question
As a member of the operations team, you need to run a script on a virtual machine created by Terraform. Which provisioned is best to use in your Terraform code?
Options
- Alocal-exec
- Bfile
- Cnull-exec
- Dremote-exec
How the community answered
(28 responses)- A7% (2)
- B4% (1)
- C4% (1)
- D86% (24)
Why each option
To execute a script directly on a virtual machine managed by Terraform, the `remote-exec` provisioner is the most appropriate choice. This provisioner allows Terraform to connect to a remote resource using SSH or WinRM and run commands or scripts.
The `local-exec` provisioner runs commands on the machine where Terraform is being executed, not on the remote virtual machine.
The `file` provisioner is used to upload files to a remote resource, not to execute scripts on it.
`null-exec` is not a standard or recognized Terraform provisioner; there might be a typo and it could refer to `null_resource`, which is a different concept.
The `remote-exec` provisioner is specifically designed to invoke a script or execute commands on a remote resource, such as a virtual machine, after it has been created. It connects to the instance using SSH for Linux or WinRM for Windows and executes the specified commands.
Concept tested: Terraform remote-exec provisioner
Source: https://developer.hashicorp.com/terraform/language/resources/provisioners/remote-exec
Topics
Community Discussion
No community discussion yet for this question.