# Infrastructure as code

> Describing servers, networks and databases in files instead of clicking.

- Level: Intermediate
- Topics: Cloud
- URL: https://tidbit.legios.com.ar/infrastructure-as-code/
- In Spanish: [Infraestructura como código](https://tidbit.legios.com.ar/es/infrastructure-as-code/)

**Infrastructure as code** (**IaC**) means writing down the cloud resources you need in a text file and letting a tool create them. Instead of clicking through the AWS console to make a virtual machine, a bucket and a database, you write "one Amazon EC2 instance of this size, one Amazon S3 bucket with this name, one Amazon RDS database", run a command, and the tool makes the cloud match the file.

The big win is repeatability. The file lives in Git next to the application code, so every change is reviewed, has an author and can be undone. Need an identical staging environment? Run the same file again. Someone deleted a server by accident? Re-apply and it comes back. Clicking gives you none of that, and nobody remembers what was clicked six months ago.

The common tools are **Terraform** (works with every cloud, with its own language called HCL), AWS CloudFormation (AWS only, in YAML or JSON), Pulumi and the AWS CDK (both use regular programming languages). All of them compare what the file says with what exists and show a plan ("will create 2, change 1, destroy 0") before touching anything.

## An analogy

A written recipe instead of a chef's memory. With the recipe on paper, any kitchen can cook the same dish tonight, next week or in another city, and a typo in it is visible before dinner, not during.

## Keep in mind

- Infrastructure files are versioned, reviewed and reused like application code.
- Tools show a plan of changes before applying them.
- Terraform is multi-cloud; CloudFormation and CDK are AWS-native.
- "Drift" is when someone changes things by hand and the file no longer matches reality.

## Go deeper

- [What is infrastructure as code? (AWS)](https://aws.amazon.com/what-is/iac/)
- [What is Terraform? (official docs)](https://developer.hashicorp.com/terraform/intro)
- [Infrastructure as code (Wikipedia)](https://en.wikipedia.org/wiki/Infrastructure_as_code)

## Related terms

- [Cloud computing](https://tidbit.legios.com.ar/cloud-computing/): Renting computers over the internet instead of buying your own.
- [Virtual machine](https://tidbit.legios.com.ar/virtual-machine/): A complete computer made of software, running inside a real one.
- [Database](https://tidbit.legios.com.ar/database/): An organized store of data that programs can search and update safely.
- [Amazon EC2](https://tidbit.legios.com.ar/amazon-ec2/): Virtual computers you rent by the hour, in any size, and switch off when done.
- [Amazon S3](https://tidbit.legios.com.ar/amazon-s3/): A giant online drawer for files, rented by the gigabyte.
- [Amazon RDS](https://tidbit.legios.com.ar/amazon-rds/): A ready-made relational database that AWS keeps patched, backed up and running.
- [Git](https://tidbit.legios.com.ar/git/): A time machine for code: every change saved, by whom and why.
- [Server](https://tidbit.legios.com.ar/server/): A computer whose job is to answer requests from other computers, all day, every day.
