1. Declarative infrastructure as code #
Describing the desired state.
Principle #
With Terraform, you describe the desired state of the infrastructure in HCL files; Terraform computes the actions needed to get there (create, modify, delete) and runs them in the right order thanks to a dependency graph.
2. The workflow #
init, plan, apply, destroy.
Commands #
terraform init # télécharge les fournisseurs, configure le backend
terraform fmt -recursive && terraform validate
terraform plan -out=plan.tfplan
terraform apply plan.tfplan
terraform output
terraform destroy # supprime tout ce que gère cette configurationReading a plan #
| Symbol | Meaning |
|---|---|
+ | Creation |
~ | In-place update |
-/+ | Replacement (destroy then create) |
- | Destruction |
3. The ecosystem #
Terraform, OpenTofu, HCP Terraform.
Overview #
| Tool | Description |
|---|---|
| Terraform | HashiCorp's tool (BSL license since 2023) |
| OpenTofu | Open source fork (MPL 2.0) from the Linux Foundation, compatible |
| HCP Terraform | Managed service: remote state, runs, policies, private registry |
| Terraform Registry | Public providers and modules |
Good practice: Pin the version of Terraform and the providers (required_version, required_providers) for reproducible runs.
