Key takeaways
- Terraform is declarative: you describe the end state and it works out the steps.
- The core workflow is write, init, plan, apply and, when needed, destroy.
- State records what Terraform manages, so protect it and store it remotely for teams.
- Variables, outputs and modules keep code reusable and clean.
- Always read the plan before applying, and never put secrets in code.
What is Terraform notes?
What is infrastructure as code?
Infrastructure as code (IaC) means defining servers, networks and services in text files that can be versioned, reviewed and repeated, instead of clicking in a console. Benefits are consistency across environments, a review trail, fast rebuilds and less manual error. Terraform is one popular IaC tool; others include cloud-specific templates.
What is the Terraform workflow?
- Write configuration in
.tffiles. terraform initdownloads providers and sets up the working folder.terraform fmtandterraform validateformat and check the code.terraform planshows what will be created, changed or destroyed.terraform applymakes the changes after confirmation.terraform destroyremoves managed resources.
Always read the plan; it is your safety check.
What are providers and resources?
A provider is a plugin that talks to a platform's API (for example AWS, Azure, Google Cloud or Kubernetes). A resource is one object you manage, such as a virtual machine or a storage bucket.
terraform {
required_providers {
aws = { source = "hashicorp/aws", version = "~> 5.0" }
}
}
provider "aws" {
region = var.region
}
resource "aws_s3_bucket" "logs" {
bucket = "example-logs-${var.env}"
tags = { Environment = var.env }
}
Pin provider versions so that results are repeatable.
How do variables and outputs work?
Input variables make code reusable; outputs print or share values; locals name expressions.
variable "env" {
type = string
description = "Environment name"
default = "dev"
}
output "bucket_name" {
value = aws_s3_bucket.logs.bucket
}
Set values with a .tfvars file, environment variables or the command line. Mark sensitive values with sensitive = true so they are hidden in output.
What is state?
Terraform stores what it manages in a state file. It compares state, configuration and real infrastructure to decide what to change. State can contain sensitive data, so do not commit it to Git. For teams, use remote state in a shared backend with locking, which stops two people applying at once. Never edit state by hand; use terraform state commands when a change is needed.
What are data sources?
A data source reads information that already exists, such as an existing network or the latest machine image, without managing it. Use it to reference resources created elsewhere.
What are modules?
A module is a folder of Terraform files that you call from another configuration, like a reusable function. Use modules for repeated patterns such as a network or a web service. Keep modules small, give them clear inputs and outputs and version them.
How do dependencies work?
Terraform builds a graph from references: if a resource uses another resource's attribute, it creates the first one first. Use depends_on only when a dependency cannot be seen from references.
How do I handle several environments?
Use separate state per environment, either through separate folders or workspaces, and pass environment-specific values with variable files. Keep the same modules across environments so that differences are small and visible.
What are safe practices?
Store code in Git and review changes through pull requests. Run plan in a pipeline and require approval before apply. Use least-privilege credentials from the environment, never in code. Tag resources for ownership and cost tracking. Test changes in a non-production environment first, and use prevent_destroy on critical resources.
What are common mistakes?
Committing state or secrets, applying without reading the plan, changing resources by hand so that they drift from code, using unpinned versions and putting too much in one state file.
How do I practise safely?
Use a free or practice account, set a budget alert and begin with cheap resources such as a storage bucket or a small virtual machine. Run plan often, apply, inspect the result in the console and then run destroy so that nothing keeps costing money. Keep your practice code in Git and write a short readme of what each folder builds.
How does Terraform compare with configuration tools?
Terraform mainly provisions infrastructure, such as networks and servers. Configuration tools install and configure software on servers after they exist. Many teams use both, or replace the second step with container images. Know the difference and give an example of each.
What should I read next?
After these notes, study how to build a small network and a web server with modules, how to set up remote state with locking and how to run Terraform in a pipeline with a plan-then-approve step. Read the provider documentation for the cloud you use, since arguments and behaviour differ between providers.
Download Terraform Notes PDF
Terraform Notes PDF
The PDF carries the same content as this page in a clean, print-ready layout, so you can read it offline and keep it for revision.
4 pages · 117 KB · PDF · Updated 5 Nov 2026