planby hand1want = {2 "web-1": "small",3 "web-2": "small",4}PLAN · APPLYWEB-1tinyWEB-2—OLD-1small~ web-1 tiny → small+ web-2 small- old-1 smallWEB CONSOLE
Back: the file you write, the IaC tool, and the cloud's three server slotsFront: the printed plan, and the web console (changes by hand)Packet: the file's wishes travelling through plan and applyInfrastructure as code: the servers you want are written in a file, and a tool makes the cloud match it. The tool reads what really exists, prints a plan (~ update web-1, + create web-2, - destroy old-1), and applies it one action at a time. Run again, nothing changes; a change made by hand (drift) is spotted and put back; and the same file rebuilds everything from nothing. The Python program is a toy that shows the idea; its have dict stands for the servers the tool manages, as they really are. Real tools (Terraform, OpenTofu, Pulumi, AWS CloudFormation) call the cloud provider's API to read and change real resources, handle dependencies between them, and save a state file.

The idea

  1. Infrastructure as code (IaC) means describing servers, networks and other cloud parts in text files. A tool reads the file and makes the real cloud match it. The file lives in version control, like any other code.

Plan

Apply

Living with it

What happens

;; step 1/11 · iac
file (what you want)  →  tool  →  cloud (what exists)

kept in version control (Git)
reviewed, repeatable, rebuildable
tools: Terraform, OpenTofu, Pulumi,
       CloudFormation, kubectl apply

The Python program is a toy that shows the idea; its have dict stands for the servers the tool manages, as they really are. Real tools (Terraform, OpenTofu, Pulumi, AWS CloudFormation) call the cloud provider's API to read and change real resources, handle dependencies between them, and save a state file. In Terraform the same wish is written in HCL, for example resource "aws_instance" "web_1" { instance_type = "t3.small" ... }. terraform plan prints the actions with + (create), ~ (update in place) and - (destroy), then a summary such as "Plan: 1 to add, 1 to change, 1 to destroy."