Your First Terraform Configuration
Last updated on 2025-11-30 | Edit this page
Overview
Questions
- How do I create a Terraform project?
- What is a
main.tffile and what belongs in it? - How does Terraform know what cloud resources to manage?
Objectives
- Create a new Terraform working directory.
- Write a minimal
main.tffile. - Initialize Terraform and interpret the output.
- Explain how providers connect Terraform to AWS.
Creating the Terraform Project Directory
Terraform works inside a folder that contains configuration files,
usually ending in .tf. Start by creating a clean
directory:
Inside that folder, we create our first configuration file.
Writing a Minimal main.tf
A minimal Terraform configuration needs two blocks:
- A required provider declaration
- A provider configuration (here, AWS)
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
provider "aws" {
region = "us-west-2"
}
What this does
- The
terraformblock tells Terraform which provider plugin to use. - The
provider "aws"block sets your AWS region. - Terraform does not create any infrastructure yet. It only knows how to talk to AWS.
Terraform Supports Many Providers
Although this lesson focuses on AWS, Terraform can manage
infrastructure across hundreds of platforms.
A provider is a plugin that enables Terraform to create,
update, and destroy resources within an ecosystem.
Common categories of Terraform providers include:
Cloud platforms
AWS, Azure, Google Cloud, Oracle Cloud, DigitalOcean, LinodeVersion control and CI/CD
GitHub, GitLab, Bitbucket, CircleCIContainers & orchestration
Kubernetes, Helm, DockerNetworking & security
Cloudflare, Palo Alto Networks, Okta, Auth0Databases & analytics
PostgreSQL, MySQL, Snowflake, DatabricksSaaS & productivity tools
PagerDuty, Datadog, New Relic, Fastly
Terraform’s strength is that it provides a single workflow for all these platforms, even though they typically use very different APIs.
Initialize Terraform
Before Terraform can do anything, it needs to download provider plugins:
You should see output confirming that the AWS provider was installed.
Running Your First Plan
Even though we haven’t defined resources yet, it’s safe to run:
Expected output:
No changes. Your infrastructure matches the configuration.
This means:
- Terraform is working correctly
- Terraform can talk to AWS
- Terraform sees no resources yet (because we haven’t defined any)
Why is this useful?
This episode establishes the foundation.
If init and plan work now, troubleshooting
future problems becomes much easier.
Most Terraform issues start with authentication or provider errors.
- Terraform configurations live in directories containing
.tffiles. - The
terraformandproviderblocks define how Terraform interacts with AWS. -
terraform initdownloads provider plugins. -
terraform planpreviews changes, even when the configuration is empty. - A clean plan confirms your AWS authentication is working.