0
0
Terraformcloud~10 mins

Why provisioners are a last resort in Terraform - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a null_resource with a local-exec provisioner.

Terraform
resource "null_resource" "example" {
  provisioner "local-exec" {
    command = [1]
  }
}
Drag options to blanks, or click blank then click option'
Aecho Hello World
B"run echo Hello World"
C"echo Hello World"
Drun echo Hello World
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the command string.
2fill in blank
medium

Complete the code to add a remote-exec provisioner that runs a shell command.

Terraform
resource "null_resource" "example" {
  provisioner "remote-exec" {
    inline = [1]
  }
}
Drag options to blanks, or click blank then click option'
Asudo apt-get update
B"sudo apt-get update"
C"[sudo apt-get update]"
D["sudo apt-get update"]
Attempts:
3 left
💡 Hint
Common Mistakes
Using a plain string instead of a list for inline commands.
3fill in blank
hard

Fix the error in the provisioner block by completing the missing argument.

Terraform
resource "null_resource" "example" {
  provisioner "remote-exec" {
    connection {
      type     = [1]
      user     = "ubuntu"
      host     = self.private_ip
    }
    inline = ["echo Hello"]
  }
}
Drag options to blanks, or click blank then click option'
Assh
Bhttp
Clocal
Dwinrm
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'http' or 'local' as connection type causes errors.
4fill in blank
hard

Fill both blanks to correctly configure a null_resource with triggers and a local-exec provisioner.

Terraform
resource "null_resource" "example" {
  triggers = {
    always_run = [1]
  }
  provisioner "local-exec" {
    command = [2]
  }
}
Drag options to blanks, or click blank then click option'
Atimestamp()
B"echo Running provisioner"
Ctrue
D"run provisioner"
Attempts:
3 left
💡 Hint
Common Mistakes
Using boolean true instead of timestamp() in triggers.
Not quoting the command string.
5fill in blank
hard

Fill all three blanks to create a remote-exec provisioner with SSH connection and inline commands.

Terraform
resource "null_resource" "example" {
  connection {
    type     = [1]
    user     = [2]
    host     = self.public_ip
  }
  provisioner "remote-exec" {
    inline = [[3]]
  }
}
Drag options to blanks, or click blank then click option'
Assh
B"ubuntu"
C"sudo systemctl restart nginx"
D"admin"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong connection type.
Not quoting the username or commands.