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
Hands-on #
Guided steps, with their solution.
1. Write the module
Why? A good module enforces best practices by default (versioning, public access block).
Createmodules/bucketwith validated variables, resources and output.2. Test the module
Why? The mock provider makes tests instant and independent of any cloud.
Writemodules/bucket/tests/bucket.tftest.hcland run the tests.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. 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
Sign in to track your progress and take notes. Sign in
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...