StoicBuilder

HandbookX the PortusInfrastructure as code

Xthe Portus, Ship it

Infrastructure as code

1 min readUpdated 28 November

In plain words

Infrastructure as code describes your servers, databases, DNS and permissions in files kept in git, and a tool such as Terraform, OpenTofu or Pulumi creates or changes the real resources to match.

Where you see it

Harbor's staging was set up by hand in a cloud console two years ago, and nobody knows why it differs from production. With the setup in Terraform files, a pull request shows every change to the infrastructure, and terraform plan lists what will be created, changed or destroyed before anything happens.

Terminalterminal
$ terraform plan # aws_db_instance.harbor will be updated in-place ~ instance_class = "db.t4g.medium" -> "db.t4g.large" # aws_s3_bucket.invoices will be destroyed - resource "aws_s3_bucket" "invoices" { Plan: 0 to add, 1 to change, 1 to destroy.
Read the plan before you apply it. Here a bucket of customer invoices is about to be deleted.

What goes wrong

  1. Applying without reading the plan

    A renamed resource can show up as destroy and create, which for a database means losing its data. Read every destroy line, use moved blocks for renames, and protect important resources with prevent_destroy.

  2. Fixing things by hand in the console

    A quick change clicked into the AWS console isn't in the code, so the next apply undoes it, or the files stop describing reality. Make every change through the code, and run plan regularly to spot drift.

  3. Secrets in the state file

    Terraform keeps a state file that can hold passwords and keys in plain text. Store it in an encrypted remote backend with limited access, never in git.

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
Make this change in our Terraform files rather than in the cloud console, then run terraform plan and paste the full output. Point out every resource that will be destroyed or replaced, and don't run terraform apply; I'll do that after reading the plan.

Quick check

Sign in to earn +10 XP for it

terraform plan for a small rename in Harbor's config says 1 to add, 0 to change, 1 to destroy, and the resource is the production database. What do you do?

Got a prompt that touches infrastructure as code?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.