tezvyn:

Infrastructure as Code: Manage Servers with Code, Not Clicks

AI-drafted, machine-checkedSource: Wikipedia: Infrastructure as codeintermediate

Infrastructure as Code (IaC) treats servers and networks like software: defined in files and versioned in Git. It's used to automate cloud resource provisioning on AWS or GCP, ensuring consistent, repeatable environments.

WHY IT EXISTS: Before IaC, setting up servers was a manual, error-prone process of clicking through UIs or running one-off commands. This led to 'configuration drift,' where environments that should be identical slowly diverged, causing 'it works on my machine' problems at scale. IaC was created to make infrastructure provisioning deterministic, repeatable, and auditable.

THE MENTAL MODEL: Think of your infrastructure—servers, load balancers, databases, network rules—as a software application. Its source code is a set of definition files. You write code to describe the desired state of your infrastructure, check it into version control (like Git), and use a tool to make reality match your code. You don't manually tweak a running server; you update the code and redeploy.

HOW IT WORKS: IaC tools operate in two main ways. The imperative approach is a script of commands: 'create a VM, then install this package, then start this service.' It's fragile because it doesn't know the current state. The declarative approach, which is more common and robust, is a definition of the target state: 'I want three servers with this software installed.' The IaC tool (like Terraform or CloudFormation) then figures out the necessary API calls to create, update, or delete resources to reach that state, regardless of the starting point.

WHEN TO USE IT: IaC is essential for any system that requires consistency and automation. Use it for provisioning cloud resources (VMs, databases, Kubernetes clusters), configuring CI/CD pipelines, creating disposable environments for development or testing, and implementing disaster recovery plans where you need to rebuild an entire stack from scratch quickly.

WHEN NOT TO USE IT: For a single, static server that will never be replicated or rebuilt (a rare 'pet' server), the overhead of setting up IaC might not be worthwhile. It's also overkill for quick, one-off experiments that won't be productized. The primary value of IaC comes from managing complexity and scale; without that, it can feel like premature optimization.

ONE CANONICAL EXAMPLE: Instead of logging into the AWS console to create a server, you write a definition in a Terraform file, main.tf: resource "aws_instance" "web" { ami = "ami-0c55b159cbfafe1f0" instance_type = "t2.micro" } Then you run 'terraform apply' in your terminal. Terraform communicates with the AWS API to provision the EC2 instance. To change the instance type, you edit the file and run 'apply' again. The file is the single source of truth.

Read the original → en.wikipedia.org

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.