Skip to main content
In this lesson, we’ll break down the fundamental components that make Terraform a reliable, infrastructure-as-code (IaC) tool. Understanding these building blocks — Terraform Core, Providers, Resources, State, and Modules — helps you design predictable, repeatable infrastructure and collaborate safely across teams.
  • Terraform Core
  • Providers
  • Resources
  • State
  • Modules

Terraform Core

Terraform Core is the CLI binary that reads and interprets your Terraform configuration files (.tf). When you run terraform init, terraform plan, or terraform apply, you are interacting with Terraform Core. Its responsibilities include:
  • Parsing configuration files and building a dependency graph.
  • Comparing your declared configuration against the current state.
  • Determining a plan of changes and orchestrating provider API calls to create, update, or destroy resources.
Terraform Core is provider-agnostic: it defines the workflow and execution model while delegating resource-specific operations to providers.

Providers

Providers are plugins that extend Terraform Core with the logic to manage resources on a particular platform (AWS, Azure, Google Cloud, GitHub, etc.). Providers implement the mappings between Terraform resource declarations and platform API calls. A minimal provider block:
provider "aws" {
  region = "us-east-1"
}
Notes about providers:
  • Version pin providers to ensure reproducible behavior.
  • Providers may require credentials and specific configuration (environment variables, shared configs, or explicit blocks).
  • Provider plugins are installed during terraform init.

Resources

Resources are the primary declarations that describe the infrastructure objects Terraform will manage — compute instances, networks, databases, DNS records, and more. Each resource block contains arguments (inputs) and exposes attributes (outputs) that can be referenced elsewhere. Example resource:
resource "aws_instance" "web" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "t3.micro"

  tags = {
    Name = "example-web"
  }
}
Key resource concepts:
  • Attributes such as IDs and computed values are stored in state and can be referenced using interpolation.
  • Lifecycle meta-arguments (create_before_destroy, prevent_destroy) control how Terraform updates resources.
  • Resource dependencies are inferred from references; explicit depends_on can enforce ordering when needed.

State

Terraform state is the authoritative record of what Terraform manages in the real world. It maps resources in your configuration to real-world objects, stores metadata (IDs, attributes), and enables Terraform to compute incremental diffs. State enables:
  • Mapping real resources to configuration.
  • Accurate planning and targeted updates.
  • Sensitive metadata persistence (resource IDs, ARNs, endpoints).
Remote state and locking are critical for team workflows. Example S3 backend with DynamoDB locking:
terraform {
  backend "s3" {
    bucket         = "my-terraform-state-bucket"
    key            = "project-name/terraform.tfstate"
    region         = "us-east-1"
    dynamodb_table = "terraform-lock-table"
  }
}
Remote state backends enable team collaboration, state locking, and recovery. Use them for shared environments to avoid state conflicts and accidental overwrites.
Terraform state can contain sensitive information (secrets, IDs, endpoints). Use encrypted storage, restrict access, and avoid committing state files to source control.

Modules

Modules are reusable, composable packages of Terraform configuration — the primary method to encapsulate and share common infrastructure patterns. Think of modules as functions or libraries for infrastructure. Calling a module:
module "vpc" {
  source = "git::https://example.com/terraform-modules.git//vpc"
  cidr   = "10.0.0.0/16"
  region = "us-east-1"
}
Module best practices:
  • Keep modules focused and opinionated.
  • Expose inputs (variables) and outputs (outputs) for composability.
  • Version and publish modules (Terraform Registry, Git tags) for stability.
The image is a diagram of Terraform's core components, including Terraform Core, Providers, Resources, State, and Modules, with brief descriptions of each.

Component Overview

  • Terraform Core: Orchestrates the execution model and dependency graph.
  • Providers: Implement API interactions for specific platforms.
  • Resources: Declare the desired infrastructure objects.
  • State: Records the current status and metadata of managed resources.
  • Modules: Package reusable configuration patterns.

Summary Table

ComponentRoleExample
Terraform CoreExecution engine; builds dependency graph and applies changesCLI commands: terraform init, terraform plan, terraform apply
ProviderTranslates resources to API calls for a platformprovider "aws" { region = "us-east-1" }
ResourceDeclares infrastructure objects to manageresource "aws_instance" "web" { ... }
StatePersists mapping and metadata of managed resourcesbackend "s3" { ... }
ModuleReusable configuration packagemodule "vpc" { source = ".../vpc" }

Next steps and further reading

  • Try creating a small configuration that includes a provider, a resource, and remote state.
  • Explore Modules to reduce duplication and enforce standards across projects.

Watch Video