Member-only story
Terraform Fundamentals: From main.tf to State, Variables, and Outputs
Terraform is a declarative provisioning tool that defines and provisions infrastructure as code: you write what you want, and Terraform figures out how to get there.
That distinction is the answer to almost every question people get stuck on while learning Terraform. Why doesn’t a second machine appear when you run terraform apply twice? How does Terraform know you have two resources? What does Terraform think about a machine you deleted from the console? All of it comes down to the same logic: Terraform compares the desired state you wrote with the current state on the provider side, and applies only the difference.
This article lays out Terraform’s basic skeleton, starting from creating an EC2 instance from scratch and moving on to adding providers, destroying resources, how the terraform.tfstate file works, parameterization with variables, and extracting data with outputs. The examples use AWS, but the logic is the same for every provider.
Your first infrastructure: main.tf
The minimum you need to stand up infrastructure in Terraform is a single file: main.tf. You describe the infrastructure inside it, see what will happen with terraform plan, and create it on AWS with terraform apply.









