0
0
Terraformcloud~20 mins

Remote-exec provisioner in Terraform - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Remote-exec Provisioner Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
2:00remaining
What is the output of this Terraform remote-exec provisioner block?
Given the following Terraform resource configuration, what will be the output when the remote-exec provisioner runs successfully?
Terraform
resource "aws_instance" "example" {
  ami           = "ami-12345678"
  instance_type = "t2.micro"

  provisioner "remote-exec" {
    inline = [
      "echo Hello World > /tmp/hello.txt",
      "cat /tmp/hello.txt"
    ]

    connection {
      type        = "ssh"
      user        = "ec2-user"
      private_key = file("~/.ssh/id_rsa")
      host        = self.public_ip
    }
  }
}
AThe provisioner will create /tmp/hello.txt but will not output anything in the logs.
BThe provisioner will fail because the file /tmp/hello.txt does not exist before the echo command.
CThe file /tmp/hello.txt will contain 'Hello World' and the provisioner outputs 'Hello World' in logs.
DThe provisioner will output an error due to missing sudo privileges.
Attempts:
2 left
💡 Hint
Think about what the inline commands do and how remote-exec outputs command results.
Configuration
intermediate
2:00remaining
Which option correctly configures a remote-exec provisioner with a WinRM connection?
You want to run a remote-exec provisioner on a Windows instance using WinRM. Which configuration snippet is correct?
A
connection {
  type     = "winrm"
  user     = "Administrator"
  password = var.winrm_password
  host     = self.private_ip
  https    = true
}
B
connection {
  type     = "ssh"
  user     = "Administrator"
  password = var.winrm_password
  host     = self.public_ip
}
C
connection {
  type     = "winrm"
  user     = "Administrator"
  private_key = file("~/.ssh/id_rsa")
  host     = self.public_ip
}
D
connection {
  type     = "winrm"
  user     = "Administrator"
  password = var.winrm_password
  host     = self.public_ip
  https    = false
}
Attempts:
2 left
💡 Hint
WinRM uses username and password, not SSH keys, and can use HTTP or HTTPS.
Architecture
advanced
2:00remaining
What is the main risk of using remote-exec provisioner in Terraform for production infrastructure?
Consider a production environment where Terraform uses remote-exec provisioners to configure instances after creation. What is the biggest architectural risk of this approach?
ARemote-exec provisioners always fail if the instance is in a private subnet.
BRemote-exec provisioners can cause configuration drift because they run outside Terraform's state management.
CRemote-exec provisioners automatically rollback changes if the script fails.
DRemote-exec provisioners require manual approval before running.
Attempts:
2 left
💡 Hint
Think about how Terraform tracks resources and what happens when changes happen outside Terraform.
security
advanced
2:00remaining
Which option describes a security best practice when using remote-exec provisioners?
When using remote-exec provisioners in Terraform, which practice improves security?
AUse ephemeral SSH keys and limit their scope to the provisioning session only.
BStore private keys in the Terraform configuration files for easy access.
CUse the root user for all remote-exec connections to avoid permission issues.
DDisable all firewall rules to allow unrestricted access during provisioning.
Attempts:
2 left
💡 Hint
Think about minimizing exposure of credentials and limiting access.
🧠 Conceptual
expert
2:00remaining
What happens if a remote-exec provisioner command fails during Terraform apply?
During a Terraform apply, a remote-exec provisioner runs a command that returns a non-zero exit code. What is Terraform's behavior?
ATerraform stops the apply process and marks the resource creation as failed, rolling back changes if possible.
BTerraform ignores the error and continues applying other resources.
CTerraform retries the command indefinitely until it succeeds.
DTerraform completes the apply but marks the resource as tainted.
Attempts:
2 left
💡 Hint
Consider how Terraform treats provisioner failures during resource creation.