Your DevOps study space

Real explanations. Videos with tests. Fresh exams every time. Keep the streak alive and watch the XP stack up.

Infrastructure as Code with Terraform · DevOps Docs · StackwisePlanDevOps Infrastructure as Code with Terraform · DevOps Docs · StackwiseCodePython Infrastructure as Code with Terraform · DevOps Docs · StackwiseBuildDocker Infrastructure as Code with Terraform · DevOps Docs · StackwiseTestDevOps Infrastructure as Code with Terraform · DevOps Docs · StackwiseReleaseGit Infrastructure as Code with Terraform · DevOps Docs · StackwiseDeployKubernetes Infrastructure as Code with Terraform · DevOps Docs · StackwiseOperateLinux Infrastructure as Code with Terraform · DevOps Docs · StackwiseMonitorDevOps

Pick a topic

Eight tracks, each with docs, a cheat sheet, videos and tests.

How it works

One loop, repeated until it sticks.

Jump back in

Picked up from where you left off.

Free forever

Your DevOps journey starts with one click.

Sign in with Google or GitHub to open every chapter, video, test and challenge. Your progress is saved wherever you learn.

Infrastructure as Code with Terraform

The Concepts chapter showed four Terraform commands and one resource. This chapter builds a small but complete project: how a Terraform configuration is structured, what actually happens during plan and apply, why the state file matters so much, and the mistakes that bite most beginners.

Why Infrastructure as Code

Clicking through the AWS console works once. It doesn't tell anyone what you clicked, it can't be reviewed, and rebuilding the same setup for staging or after an accident is guesswork. With IaC the files are the documentation, changes go through pull requests like code, and apply produces the same result every time. Terraform is declarative (you describe the end state, it works out the steps) and works with hundreds of platforms through providers. Since 2023 Terraform is under the BSL licence; OpenTofu is an open-source fork with the same language and a tofu command.

The building blocks

  • Provider: a plugin that talks to one platform's API (AWS, Azure, Cloudflare, GitHub…). Terraform downloads it during init.
  • Resource: one thing to create and manage, written resource "TYPE" "NAME". Its address, like aws_s3_bucket.site, is how you refer to it elsewhere.
  • Variable: an input, so the same code works for different names, regions or environments.
  • Output: a value printed after apply (an IP, a URL, an ARN) and readable by other tools.
  • Data source: reads something that already exists without managing it, like the latest Ubuntu AMI.

Terraform loads every .tf file in the folder together, so splitting into files is just for readability.

A small, complete example: a private S3 bucket

# main.tf
terraform {
  required_version = ">= 1.5"
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 6.0"          # any 6.x, never a surprise 7.0
    }
  }
}

provider "aws" {
  region = var.region
}

resource "aws_s3_bucket" "site" {
  bucket = var.bucket_name
  tags = {
    Project   = "devops-practice"
    ManagedBy = "terraform"
  }
}

resource "aws_s3_bucket_versioning" "site" {
  bucket = aws_s3_bucket.site.id     # a reference: Terraform creates the bucket first
  versioning_configuration {
    status = "Enabled"
  }
}

resource "aws_s3_bucket_public_access_block" "site" {
  bucket                  = aws_s3_bucket.site.id
  block_public_acls       = true
  block_public_policy     = true
  ignore_public_acls      = true
  restrict_public_buckets = true
}

# variables.tf
variable "region" {
  type    = string
  default = "eu-central-1"
}

variable "bucket_name" {
  description = "Globally unique S3 bucket name"
  type        = string
}

# outputs.tf
output "bucket_arn" {
  value = aws_s3_bucket.site.arn
}

# terraform.tfvars  (loaded automatically)
bucket_name = "demee-devops-practice-2026"

References like aws_s3_bucket.site.id tell Terraform about dependencies, so it knows the bucket must exist before its versioning and access settings. Terraform finds AWS credentials the same way the AWS CLI does (aws configure, AWS_PROFILE, or environment variables). Never write access keys in a .tf file.

The workflow: init, plan, apply, destroy

main.tfwhat you wantstatewhat existsterraform planthe differenceterraform applymakes the changesreal resourcesS3, EC2, VPC...you type yesstate updated
Plan is a dry run you can read; apply does exactly that plan. The state file is how Terraform knows which real resource each block in your code means.
$ terraform init       # download providers and modules, set up the backend
$ terraform fmt        # format the files
$ terraform validate   # catch syntax and type errors without touching AWS
$ terraform plan
  # aws_s3_bucket.site will be created
  + resource "aws_s3_bucket" "site" {
      + arn    = (known after apply)
      + bucket = "demee-devops-practice-2026"
      ...
Plan: 3 to add, 0 to change, 0 to destroy.

$ terraform apply      # shows the plan again, asks you to type "yes"
Apply complete! Resources: 3 added, 0 changed, 0 destroyed.
Outputs:
bucket_arn = "arn:aws:s3:::demee-devops-practice-2026"

$ terraform destroy    # delete everything this configuration manages

Read plans carefully: + create, ~ update in place, - destroy, and -/+ destroy and re-create. Some attribute changes (like a bucket's name) can't be made in place, and -/+ on a database means losing its data. In CI, save the reviewed plan with terraform plan -out=tfplan and run terraform apply tfplan, so exactly what was reviewed is applied.

State, remote state and locking

After apply, Terraform writes terraform.tfstate: a JSON map from each resource address to the real object's ID and attributes. That's how it knows aws_s3_bucket.site is that bucket, and what to change next time. Two big problems with keeping it on your laptop: teammates don't have it, and it contains secrets in plain text (database passwords, keys). Teams use a remote backend:

terraform {
  backend "s3" {
    bucket       = "demee-terraform-state"
    key          = "practice-site/terraform.tfstate"
    region       = "eu-central-1"
    encrypt      = true
    use_lockfile = true      # S3-native locking (Terraform 1.10+)
  }
}

Locking stops two people (or two pipelines) running apply at the same time and corrupting the state. Older setups used a DynamoDB table for this; since Terraform 1.11 that option is deprecated in favour of use_lockfile. Other backends include HCP Terraform, Azure Blob Storage and Google Cloud Storage. Backend blocks can't use variables, and after changing one you run terraform init again. Useful state commands: terraform state list, terraform state show aws_s3_bucket.site, terraform output.

youterraform applya teammateterraform applyCI pipelineterraform applys3 backendterraform.tfstateencryptedlock: one at a timea second apply waits for the lockAWSresources
One shared, locked state means everyone sees the same picture of what exists. A state file on one laptop is the classic way teams overwrite each other.

Modules

A module is a folder of .tf files you call like a function with inputs. Your root folder is itself a module. Write your own for repeated patterns, or use well-maintained ones from the Terraform Registry, always pinning a version:

module "vpc" {
  source  = "terraform-aws-modules/vpc/aws"
  version = "~> 6.0"
  name    = "practice"
  cidr    = "10.0.0.0/16"
}

module "logs_bucket" {
  source      = "./modules/bucket"     # your own module in a subfolder
  bucket_name = "demee-practice-logs"
}

Drift

Drift is when real infrastructure no longer matches the code, usually because someone changed it by hand in the console. terraform plan detects it ("Objects have changed outside of Terraform") and proposes changing it back. If the manual change was right, copy it into the code. terraform apply -refresh-only updates the state to match reality without changing any infrastructure. To bring an existing, hand-made resource under Terraform, write an import block (Terraform 1.5+) with the resource's address and real ID, then plan and apply.

Common mistakes

  • Committing state or secrets. Add .terraform/, *.tfstate, *.tfstate.* and any .tfvars holding secrets to .gitignore. Do commit .terraform.lock.hcl: it pins exact provider versions for everyone.
  • Hard-coded credentials in the provider block. Use profiles locally and short-lived roles (OIDC) in CI.
  • Renaming a resource in code (say site to website) makes Terraform plan a destroy and a create. Add a moved block with from = aws_s3_bucket.site and to = aws_s3_bucket.website so it just updates the state.
  • Unpinned versions: a new major provider version can change behaviour. Always set version constraints.
  • Error: No valid credential sources found: Terraform can't find AWS credentials. Run aws configure or aws sso login, or set AWS_PROFILE.
  • Error acquiring the state lock: someone else is running, or a crashed run left a lock. Wait; only if you're sure nothing is running, use terraform force-unlock LOCK_ID.
  • BucketAlreadyExists: S3 names are global across all AWS accounts. Pick a more unique name.

Questions

Pick an answer. Get it wrong and you can try again right away, no waiting. 10 questions per topic - pick a filter below, then use Recreate questions for a fresh set on that topic.

Fresh questions every time

Exam

A mixed test across the whole site, shuffled so you never know which topic comes next. When you submit, every mistake comes with the reason and a jump to the exact moment in the video that explains it.

30 questions 6 topics 20 minute limit Up to 70 XP
1–4 answer · ←→ move
History

Essay

0 / 200-250 words
Sample answer
History
0:00 / 0:00
Not started

on YouTube
Subscribe

Topic progress

Activity

Achievements

Settings

Your profile and your account.

Profile details

* Required. Saved in this browser until you sign in.

Letters, numbers, dots, dashes and underscores.
0 / 160

Account

Checking…

App

Install Stackwise on your phone or computer. It opens in its own window from your home screen, and the Docs and cheat sheets you've opened keep working without internet.

Only admins can see this

Dashboard

Sign-ups, activity, messages and reviews in one place.

Prove it

Certificates

Pass a topic's test and get a certificate with its own public page you can share or add to LinkedIn. Each test is 10 questions drawn at random and graded on the server; you need 8 right, you have 15 minutes, and you get one try per topic a day.

From first command to production

Linux for DevOps

A path through Linux the way DevOps engineers use it: ten stages, every command explained with its flags, examples, real output and mistakes, the combinations engineers chain together, and incidents worked through step by step. Practise everything in a safe lab folder.

Before the interview

Interview prep

Questions that come up in real DevOps interviews, with the kind of answer that lands. Say yours out loud first, then compare. Each one links to the chapter that goes deeper.

    Private to you

    My notes

    Everything you wrote down while watching and reading, in one place. Saved to your account, never shown to anyone.