Your First Configuration
A Terraform configuration is a folder of files that describe infrastructure. The smallest configuration is one file and one resource.
One resource block
The block names the type first, then its own name. The lines inside set its details.
resource "local_file" "hello" {
filename = "hello.txt"
content = "Hello from Terraform."
}Prepare the folder
Init downloads the provider named in the file. It runs once per folder.
terraform initPreview, then build
Plan shows what will happen. Apply makes it happen.
terraform plan
terraform applyExample
# main.tf
terraform {
required_providers {
local = {
source = "hashicorp/local"
version = "2.9.1"
}
}
}
resource "local_file" "hello" {
filename = "hello.txt"
content = "Hello from Terraform."
}
# Commands:
# terraform init
# terraform plan
# terraform apply
# terraform destroyKey points
- A configuration is a folder that holds Terraform files.
- The main file is usually called main.tf.
- A resource block describes one thing Terraform should manage.
- The local provider manages files on your own machine, so no cloud account is needed.
- Each resource has a type, such as local_file, and a name, such as hello.
- Terraform creates the file only when you run apply, not when you write the file.
The file describes one file on disk. Init prepares the folder. Plan previews the change. Apply creates the file. Destroy removes it, so practice leaves nothing behind.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Rust Playground
Exercise
Which provider does the first configuration use?