RousselTMLEARNING

Automation

Terraform: principles, architecture and workflow

Understand Terraform: declarative infrastructure as code, architecture (core, providers, state), the init, plan, apply and destroy workflow, the dependency graph, Terraform and OpenTofu, HCP Terraform.

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.

Terraform architecture
More than 4,000 providers exist: clouds, Kubernetes, DNS, monitoring, SaaS.

2. The workflow #

init, plan, apply, destroy.

Commands #

Terraform workflow
The plan has no effect: it shows what is going to change.
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 configuration

Reading a plan #

SymbolMeaning
+Creation
~In-place update
-/+Replacement (destroy then create)
-Destruction

3. The ecosystem #

Terraform, OpenTofu, HCP Terraform.

Overview #

ToolDescription
TerraformHashiCorp's tool (BSL license since 2023)
OpenTofuOpen source fork (MPL 2.0) from the Linux Foundation, compatible
HCP TerraformManaged service: remote state, runs, policies, private registry
Terraform RegistryPublic providers and modules
Good practice: Pin the version of Terraform and the providers (required_version, required_providers) for reproducible runs.

Related articles

The HCL language: resources, variables, outputs, data and expressions

Writing Terraform: terraform, provider, resource and data blocks, typed variables with validation, locals, ou…

Terraform state: remote backends, locking, import and refactoring

Manage Terraform state: the role of the state file, sensitive data, remote backends (S3, azurerm, gcs, HCP Te…

Terraform modules: designing, versioning and reusing

Structure Terraform with modules: root module and child modules, inputs and outputs, sources (local, Git, reg…

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!