0
0
Terraformcloud~10 mins

Local-exec provisioner in Terraform - Interactive Code Practice

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

Complete the code to run a local command after resource creation.

Terraform
resource "null_resource" "example" {
  provisioner "local-exec" {
    command = [1]
  }
}
Drag options to blanks, or click blank then click option'
A"echo Hello World"
B"pwd"
C"aws s3 ls"
D"terraform apply"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a command that requires AWS CLI without setup
Not putting the command in quotes
2fill in blank
medium

Complete the code to run a script file using local-exec provisioner.

Terraform
resource "null_resource" "script_runner" {
  provisioner "local-exec" {
    command = [1]
  }
}
Drag options to blanks, or click blank then click option'
A"bash deploy.sh"
B"ls -l"
C"./deploy.sh"
D"terraform init"
Attempts:
3 left
💡 Hint
Common Mistakes
Using only the script name without shell command
Using terraform commands instead of shell commands
3fill in blank
hard

Fix the error in the local-exec provisioner command to print the current directory.

Terraform
resource "null_resource" "pwd_example" {
  provisioner "local-exec" {
    command = [1]
  }
}
Drag options to blanks, or click blank then click option'
Apwd
Bcd
Cecho pwd
D"pwd"
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the command string
Using commands that do not output directory
4fill in blank
hard

Fill both blanks to run a local command that lists files in the current directory.

Terraform
resource "null_resource" "list_files" {
  provisioner "local-exec" {
    command = [1] [2]
  }
}
Drag options to blanks, or click blank then click option'
A"ls"
B"-l"
C"-a"
D"pwd"
Attempts:
3 left
💡 Hint
Common Mistakes
Using pwd instead of ls
Using options that do not list files
5fill in blank
hard

Fill all three blanks to run a local command that creates a directory named 'testdir' and lists its contents.

Terraform
resource "null_resource" "create_and_list" {
  provisioner "local-exec" {
    command = [1] && [2] [3]
  }
}
Drag options to blanks, or click blank then click option'
A"mkdir testdir"
B"ls"
C"-l"
D"rm -rf testdir"
Attempts:
3 left
💡 Hint
Common Mistakes
Using remove command instead of mkdir
Not combining commands properly