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 modules: designing, versioning and reusing
Structure Terraform with modules: root module and child modules, inputs and outputs, sources (loc...
Infrastructure as Code on Azure: Bicep, Terraform, Cost Management and Well-Architected
Describe and deploy Azure as code with Bicep (modules, parameters, what-if, pipeline deployments)...
Infrastructure as Code on AWS: CloudFormation, CDK, Terraform and Well-Architected
Describe and deploy your AWS infrastructure as code with CloudFormation, the CDK or Terraform, au...
Operating OVHcloud: Terraform, monitoring, security, costs and sovereignty
Operate OVHcloud in production: infrastructure as code with the ovh and openstack Terraform provi...
End-to-end CI/CD (1/5): principles and anatomy of a pipeline
Understand end-to-end CI/CD: continuous integration, continuous delivery and continuous deploymen...
Automation and infrastructure as code for Elasticsearch: API, Terraform, Ansible and CI/CD
Automate Elasticsearch administration: REST API and clients, the elasticstack Terraform provider ...
Operating Google Cloud: observability, security, infrastructure as code and costs
Operate Google Cloud: Cloud Monitoring, Cloud Logging and Cloud Trace (Google Cloud Observability...
Vagrant: overview and vocabulary (box, provider, provisioner, Vagrantfile)
The essential notions for following the Vagrant course: what Vagrant is for, the lifecycle of an ...
Cloud native: definition and principles of a cloud native application
What is cloud native? The CNCF definition, the principles of a cloud native application (microser...