RousselTMLEARNING

TP · Terraform: from discovery to expertise

Lab: A tested module (terraform test, tflint, Checkov)

What you will learn in this TP
  • Design a module with validations
  • Test with mock_provider
  • Analyse code security

Introduction #

What you will learn in this section
  • Design a module with validations
  • Test with mock_provider
  • Analyse code security

Context. Several teams need compliant buckets. You provide a secure-by-default, automatically tested module.

Prerequisites: Terraform 1.10 or later, Docker, LocalStack and terraform-local (pip install localstack terraform-local); no cloud account or charges  ·  Estimated time: 50 min

A secure-by-default module with automated tests and analysis.

Hands-on #

Guided steps, with their solution.

  1. 1. Write the module

    Why? A good module enforces best practices by default (versioning, public access block).

    Create modules/bucket with validated variables, resources and output.
  2. 2. Test the module

    Why? The mock provider makes tests instant and independent of any cloud.

    Write modules/bucket/tests/bucket.tftest.hcl and run the tests.
  3. 3. Analyse the code

    Why? tflint flags errors and conventions; Checkov reports security bad practices.

    Run tflint and Checkov on the module and read the findings (e.g. KMS encryption or access logging).
  4. 4. Use the module

    Why? The root module simply assembles tested modules.

    Call the module twice with for_each from the root and apply on LocalStack.

Difficulty level : ●●●○○ (3/5)

My progress

  • ⏱ Estimated time : ≈ 50 min

Sign in to track your progress and take notes. Sign in

💬 Ask a question

Recommended Articles

Les modules Terraform : concevoir, versionner et réutiliser

Structurer Terraform avec des modules : module racine et modules enfants, entrées et sorties, sou...

Tester et sécuriser Terraform : validate, terraform test, tflint, Checkov et politiques

Garantir la qualité du code Terraform : fmt et validate, tests natifs terraform test avec fournis...

Terraform : principes, architecture et flux de travail

Comprendre Terraform : infrastructure as code déclarative, architecture (cœur, fournisseurs, état...

Le langage HCL : ressources, variables, sorties, données et expressions

Écrire du Terraform : blocs terraform, provider, resource et data, variables typées avec validati...

Terraform sur plusieurs clouds : AWS, Azure, Google Cloud, OVHcloud et Kubernetes

Utiliser Terraform avec les principaux fournisseurs : aws, azurerm, google, ovh et openstack, kub...

L'état Terraform : backends distants, verrouillage, import et refactorisation

Gérer l'état Terraform : rôle du fichier d'état, données sensibles, backends distants (S3, azurer...

Terraform en CI/CD : pipelines, revue du plan, OIDC et GitOps

Automatiser Terraform : pipeline plan sur demande de fusion et apply après approbation, publicati...

Terraform multi-environnements, workspaces et organisation des dépôts

Organiser Terraform pour plusieurs environnements : dossiers par environnement, fichiers tfvars, ...

Préparer la certification HashiCorp Certified: Terraform Associate

Guide de préparation au Terraform Associate : format, objectifs officiels (concepts de l'IaC, flu...

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!