Infrastructure as code, or IaC, is the practice of describing servers, networks and databases in text files. Instead of clicking through dashboards, you write what you want, and a tool creates everything.
How it works
You write files that declare the desired resources. A tool, such as Terraform, Pulumi or each cloud's native services, reads those files and talks to the provider to create, change or remove resources.
The flow is usually:
- Write: define resources in files.
- Plan: the tool shows what will change, without applying yet.
- Apply: the tool executes the changes.
- Version: the files live in Git, with history and review.
Because the code describes the final state, running it twice gives the same result. This property is called idempotence and avoids creating duplicate resources.
Practical example
You need a server to run your AI API. Instead of creating it manually in the cloud dashboard, you write a file:
resource "aws_instance" "api" {
ami = "ami-exemplo"
instance_type = "t3.small"
tags = {
Name = "api-de-ia"
}
}The values above are fictitious. Then, in the terminal:
terraform plan
terraform applyIf tomorrow you need an identical environment for testing, just apply the same file with a different name.
What it's for
It is used to repeat environments without manual error, recover infrastructure quickly after a problem and audit changes, since everything goes through Git.
It also helps teams: infrastructure changes come in via pull request and are reviewed like code. In AI projects, it is common to use IaC to create GPU clusters, queues and vector databases in a standardized way.
Code agents can help write these files, but human review is essential before applying.
Cautions
A mistake in infrastructure code can delete real resources or generate cost. Always read the plan before applying.
Do not store secrets in files. Use environment variables or a secrets manager. And protect the state file of tools like Terraform, as it may contain sensitive data.