0
0
Terraformcloud~10 mins

File provisioner in Terraform - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - File provisioner
Start Terraform Apply
Create Resource (e.g., VM)
Trigger File Provisioner
Connect to Resource via SSH
Copy Local File to Remote Path
Confirm File Transfer Success
Finish Provisioning
Terraform Apply Complete
Terraform creates the resource, then connects via SSH to copy a local file to the remote machine before finishing.
Execution Sample
Terraform
resource "aws_instance" "example" {
  ami           = "ami-12345678"
  instance_type = "t2.micro"

  provisioner "file" {
    source      = "./app.conf"
    destination = "/tmp/app.conf"
  }
}
This code creates an AWS instance and copies the local file app.conf to /tmp/app.conf on the instance.
Process Table
StepActionEvaluationResult
1Start terraform applyN/ABegin resource creation
2Create aws_instance.exampleAMI and instance_type validInstance created and running
3Trigger file provisionerProvisioner block foundPrepare to copy file
4Connect via SSH to instanceSSH credentials validConnection established
5Copy ./app.conf to /tmp/app.confLocal file existsFile copied successfully
6Confirm file presence on instanceFile checksum matchesFile verified
7Finish provisioningAll provisioners successfulTerraform apply completes
💡 All steps completed successfully; file provisioner copied file and Terraform apply finished.
Status Tracker
VariableStartAfter Step 2After Step 5Final
aws_instance.exampleundefinedcreated (running)created (running)created (running)
file provisioner statusnot startedpendingfile copiedcompleted
Key Moments - 3 Insights
Why does Terraform need SSH access for the file provisioner?
Terraform uses SSH to connect to the remote instance to copy the file, as shown in step 4 of the execution_table.
What happens if the local file does not exist?
The file provisioner fails at step 5 because it cannot find the source file to copy, stopping the apply process.
Is the file provisioner run before or after the resource is created?
It runs after the resource is created and running, as seen between steps 2 and 3 in the execution_table.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step is the file actually copied to the instance?
AStep 5
BStep 4
CStep 3
DStep 6
💡 Hint
Refer to the 'Action' column in execution_table row 5.
According to variable_tracker, what is the status of the file provisioner after step 5?
Apending
Bfile copied
Cnot started
Dcompleted
💡 Hint
Check the 'file provisioner status' row after 'After Step 5' column.
If SSH credentials were invalid, at which step would the process fail?
AStep 2
BStep 5
CStep 4
DStep 6
💡 Hint
Look at the 'Connect via SSH to instance' action in execution_table step 4.
Concept Snapshot
Terraform File Provisioner:
- Runs after resource creation
- Uses SSH to connect to remote machine
- Copies local file to remote destination
- Fails if local file missing or SSH fails
- Useful for simple file transfers during provisioning
Full Transcript
The Terraform file provisioner runs after the resource is created. Terraform connects to the remote machine using SSH. It copies a local file to a specified path on the remote machine. The process verifies the file transfer. If the local file is missing or SSH connection fails, the provisioner stops the apply. This helps automate file setup on new resources.