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.
My progress
Sign in to track your progress and take notes. Sign in
💬 Questions about this lesson
No questions yet: be the first to ask for help or share your configuration.
Recommended Articles
Terraform in CI/CD: pipelines, plan review, OIDC and GitOps
Automate Terraform: plan pipeline on merge requests and apply after approval, posting the plan as...
The HCL language: resources, variables, outputs, data and expressions
Writing Terraform: terraform, provider, resource and data blocks, typed variables with validation...
Preparing for the HashiCorp Certified: Terraform Associate certification
Preparation guide for the Terraform Associate: format, official objectives (IaC concepts, workflo...
Terraform best practices: structure, state, security, review and maintenance
Terraform best practices for teams: repository structure, naming, pinned versions, encrypted and ...
Terraform state: remote backends, locking, import and refactoring
Manage Terraform state: the role of the state file, sensitive data, remote backends (S3, azurerm,...
Testing and securing Terraform: validate, terraform test, tflint, Checkov and policies
Ensure the quality of Terraform code: fmt and validate, native terraform test tests with mocked p...
Terraform across multiple clouds: AWS, Azure, Google Cloud, OVHcloud and Kubernetes
Use Terraform with the main providers: aws, azurerm, google, ovh and openstack, kubernetes and he...
Terraform multi-environment, workspaces and repository organization
Organize Terraform for several environments: one folder per environment, tfvars files, CLI worksp...
Infrastructure as Code and GitOps: Terraform, Ansible and Argo CD
Manage infrastructure as code: declarative or imperative, Terraform (providers, state, plan, modu...