You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
This lesson walks you through installing Terraform, understanding the directory structure, configuring your first provider, and running the core workflow: init, plan, apply, and destroy.
brew tap hashicorp/tap
brew install hashicorp/tap/terraform
wget -O - https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install terraform
choco install terraform
terraform version
# Terraform v1.x.x
A typical Terraform project looks like this:
my-project/
├── main.tf # Primary resource definitions
├── variables.tf # Input variable declarations
├── outputs.tf # Output value declarations
├── providers.tf # Provider configuration
├── terraform.tfvars # Variable values (often gitignored)
├── .terraform/ # Downloaded providers and modules (gitignored)
├── .terraform.lock.hcl # Dependency lock file (committed)
└── terraform.tfstate # State file (gitignored if using remote backend)
Tip: While you can put everything in a single
.tffile, splitting by concern (main.tf,variables.tf,outputs.tf) is a widely followed convention.
A provider is a plugin that lets Terraform interact with a specific API. You must declare which providers you need:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
required_version = ">= 1.5"
}
provider "aws" {
region = "eu-west-2"
}
| Provider | Source | Purpose |
|---|---|---|
| AWS | hashicorp/aws | Amazon Web Services |
| Azure | hashicorp/azurerm | Microsoft Azure |
| GCP | hashicorp/google | Google Cloud Platform |
| Kubernetes | hashicorp/kubernetes | Kubernetes clusters |
| GitHub | integrations/github | GitHub repositories and teams |
| Cloudflare | cloudflare/cloudflare | DNS, CDN, WAF |
| Datadog | DataDog/datadog | Monitoring and alerting |
The full provider registry is at registry.terraform.io.
Create a file called main.tf:
terraform {
required_providers {
local = {
source = "hashicorp/local"
version = "~> 2.0"
}
}
}
resource "local_file" "hello" {
content = "Hello, Terraform!"
filename = "${path.module}/hello.txt"
}
This uses the local provider to create a file on disk — no cloud credentials needed.
terraform init
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.