← All insightsAutomation

Automating Terraform from scratch

CodeWizard Academy · 16 August 2026 · 3 min read · Intermediate

Anything you do to Terraform twice should be automated. This walks the path from a manual install to a repeatable, pipeline-driven setup.

1. Install it reproducibly

bash
brew install terraform      # or download the binary from releases
terraform -install-autocomplete
terraform version

2. Describe the desired state

A minimal AWS example with remote state and a variable.

hcl
terraform {
  required_providers { aws = { source = "hashicorp/aws", version = "~> 5.0" } }
  backend "s3" {
    bucket = "acme-tfstate"
    key    = "prod/network.tfstate"
    region = "eu-west-1"
  }
}

variable "env" { type = string, default = "prod" }

resource "aws_s3_bucket" "assets" {
  bucket = "acme-${var.env}-assets"
  tags   = { Environment = var.env }
}

3. Run it from CI

Plan on every PR, apply only on main.

yaml
plan:
  stage: test
  script:
    - terraform init -input=false
    - terraform plan -input=false -out=tfplan
apply:
  stage: deploy
  script: terraform apply -input=false -auto-approve tfplan
  rules:
    - if: '$CI_COMMIT_BRANCH == "main"'

Want senior help putting Terraform to work - or a team bootcamp on it? CodeWizard runs Israel's largest DevOps community and embeds named senior engineers with a transparent hours log. Book a free consult or explore the Academy.

Like where this is going?

Get hands-on help from the engineers who write these posts.

Book a free consult