nerdexam
HashiCorp

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.

Read, generate, and modify configuration

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)
  • A
    7% (2)
  • B
    4% (1)
  • C
    4% (1)
  • D
    86% (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.

Alocal-exec

The `local-exec` provisioner runs commands on the machine where Terraform is being executed, not on the remote virtual machine.

Bfile

The `file` provisioner is used to upload files to a remote resource, not to execute scripts on it.

Cnull-exec

`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.

Dremote-execCorrect

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

#Terraform provisioners#remote-exec#VM automation#Script execution

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice