Dung (Donny) Nguyen

Senior Software Engineer

Terraform

Terraform is an open-source Infrastructure as Code (IaC) tool created by HashiCorp that lets you define, provision, and manage infrastructure across many providers using a declarative configuration language. Because it is cloud-agnostic, the same workflow works for AWS, Azure, Google Cloud, Kubernetes, and hundreds of other services through a large ecosystem of providers.

Core Concepts

HashiCorp Configuration Language (HCL)

Terraform configurations are written in HCL, a declarative language designed to be human-readable. You describe what you want, and Terraform determines how to achieve it, including the correct order of operations based on resource dependencies.

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}

provider "aws" {
  region = var.aws_region
}

variable "aws_region" {
  type    = string
  default = "us-east-1"
}

resource "aws_s3_bucket" "app_bucket" {
  bucket = "my-application-bucket"

  tags = {
    Environment = "Production"
    ManagedBy   = "Terraform"
  }
}

output "bucket_arn" {
  value = aws_s3_bucket.app_bucket.arn
}

The Terraform Workflow

terraform init      # Initialize the working directory and download providers
terraform fmt       # Format configuration files consistently
terraform validate  # Check the configuration for syntax and internal errors
terraform plan      # Preview the changes Terraform will make
terraform apply     # Apply the changes to reach the desired state
terraform destroy   # Remove all resources managed by the configuration

The key step is terraform plan, which produces an execution plan showing exactly what will be created, changed, or destroyed before anything happens.

State Management

Terraform’s state file is central to how it works. For teams, storing state locally is risky, so Terraform supports remote backends that keep state in a shared, secure location with locking to prevent concurrent modifications.

A common AWS backend uses an S3 bucket for state storage and a DynamoDB table for locking:

terraform {
  backend "s3" {
    bucket         = "my-terraform-state"
    key            = "prod/terraform.tfstate"
    region         = "us-east-1"
    dynamodb_table = "terraform-locks"
    encrypt        = true
  }
}

Modules for Reusability

Modules let you package a set of resources and reuse them across environments and projects.

module "network" {
  source     = "./modules/vpc"
  cidr_block = "10.0.0.0/16"
  environment = "production"
}

You can also consume modules from the public Terraform Registry, which hosts thousands of community and verified modules.

Advantages

Considerations

Conclusion

Terraform is one of the most popular IaC tools because of its declarative approach, cloud-agnostic design, and rich ecosystem. By defining infrastructure in HCL, managing state carefully, and following a consistent plan-and-apply workflow, teams can provision and evolve infrastructure reliably across virtually any platform.