1. The code #
Readable and predictable.
Rules #
- Standard files: main.tf, variables.tf, outputs.tf, versions.tf, README.
- Lowercase names with underscores, without repeating the resource type.
- required_version and pinned provider versions; .terraform.lock.hcl versioned.
- No hard-coded values: variables with validation, locals for computations.
2. State and security #
Protecting what is critical.
Rules #
- Remote state encrypted, versioned, locked, with restricted access.
- One state per layer and per environment.
- No secrets in the code or in versioned tfvars; sensitive variables and ephemeral values.
- lifecycle prevent_destroy on critical resources (databases, state buckets).
3. Delivery and maintenance #
Making it last.
Rules #
- Plan published and reviewed on every merge request; apply only through the pipeline.
- Automated checks: fmt, validate, tflint, Checkov, terraform test.
- Scheduled drift detection; any manual change is brought back into the code or reverted.
- Regular updates of Terraform, providers and modules (Renovate, Dependabot).
terraform fmt -check -recursive
terraform validate
tflint --recursive
checkov -d . --quiet
terraform test
terraform plan -refresh-only -detailed-exitcode # code 2 = dérive
terraform providers lock -platform=linux_amd64 -platform=darwin_arm64My 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...
Terraform: principles, architecture and workflow
Understand Terraform: declarative infrastructure as code, architecture (core, providers, state), ...
Terraform state: remote backends, locking, import and refactoring
Manage Terraform state: the role of the state file, sensitive data, remote backends (S3, azurerm,...
Preparing for the HashiCorp Certified: Terraform Associate certification
Preparation guide for the Terraform Associate: format, official objectives (IaC concepts, workflo...
Terraform multi-environment, workspaces and repository organization
Organize Terraform for several environments: one folder per environment, tfvars files, CLI worksp...
Terraform modules: designing, versioning and reusing
Structure Terraform with modules: root module and child modules, inputs and outputs, sources (loc...
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...
The HCL language: resources, variables, outputs, data and expressions
Writing Terraform: terraform, provider, resource and data blocks, typed variables with validation...