0
0
Terraformcloud~20 mins

File provisioner in Terraform - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
File Provisioner Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Configuration
intermediate
2:00remaining
File Provisioner Destination Path Behavior

You use a Terraform file provisioner to copy a file to a remote VM. What will happen if the destination path points to a directory that does not exist on the remote machine?

Terraform
provisioner "file" {
  source      = "app.conf"
  destination = "/etc/myapp/config/"
}
ATerraform creates the missing directory path automatically and copies the file inside it.
BTerraform copies the file to the user's home directory instead.
CTerraform copies the file but renames it to the directory name.
DTerraform fails with an error because the destination directory does not exist.
Attempts:
2 left
💡 Hint

Think about how file copying works on remote systems when the target folder is missing.

service_behavior
intermediate
2:00remaining
File Provisioner Execution Timing

When does the Terraform file provisioner run during the resource lifecycle?

ABefore the resource is created.
BAfter the resource is created and after all other provisioners.
CAfter the resource is created but before any <code>remote-exec</code> provisioners.
DOnly during resource destruction.
Attempts:
2 left
💡 Hint

Consider the order of provisioners in Terraform.

security
advanced
2:30remaining
File Provisioner and Sensitive Data Handling

You need to copy a sensitive configuration file containing secrets to a remote server using the Terraform file provisioner. Which approach best protects the sensitive data during provisioning?

AUse the <code>source</code> attribute pointing to a local file and rely on SSH encryption.
BStore the file content in a Terraform variable marked as sensitive and use <code>content</code> attribute in the provisioner.
CEncode the file content in base64 and decode it on the remote server after copying.
DCopy the file normally and delete it immediately after provisioning.
Attempts:
2 left
💡 Hint

Think about Terraform's sensitive variable feature and how it prevents data exposure.

Architecture
advanced
2:30remaining
File Provisioner Usage in Immutable Infrastructure

In an immutable infrastructure approach, which statement about using the Terraform file provisioner is correct?

AFile provisioners should be avoided because they modify resources after creation, breaking immutability.
BFile provisioners are ideal because they allow dynamic file changes after resource creation.
CFile provisioners are required to configure immutable resources during creation.
DFile provisioners automatically create new immutable resources when files change.
Attempts:
2 left
💡 Hint

Recall what immutable infrastructure means for resource changes.

🧠 Conceptual
expert
3:00remaining
Terraform File Provisioner Behavior on Resource Update

If you update the source file used in a Terraform file provisioner and run terraform apply without changing the resource configuration, what happens?

ATerraform does not detect changes in the source file and does not re-run the provisioner.
BTerraform throws an error about unmanaged file changes.
CTerraform detects the file change and re-runs the provisioner to update the remote file.
DTerraform destroys and recreates the resource to apply the updated file.
Attempts:
2 left
💡 Hint

Think about how Terraform tracks changes and what triggers provisioners.