What you will learn in this TP
- Design a module with validations
- Test with mock_provider
- Analyse code security
All steps and instructions are shown. Recommended for this lab: semi-guided
Introduction #
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.
Validate your work
Check that each goal above is reached and that you get the result described in the introduction.
Difficulty level : ●●●○○ (3/5)
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...
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: principles, architecture and workflow
Understand Terraform: declarative infrastructure as code, architecture (core, providers, state), ...
The HCL language: resources, variables, outputs, data and expressions
Writing Terraform: terraform, provider, resource and data blocks, typed variables with validation...
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...
Terraform state: remote backends, locking, import and refactoring
Manage Terraform state: the role of the state file, sensitive data, remote backends (S3, azurerm,...
Terraform best practices: structure, state, security, review and maintenance
Terraform best practices for teams: repository structure, naming, pinned versions, encrypted and ...
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 multi-environment, workspaces and repository organization
Organize Terraform for several environments: one folder per environment, tfvars files, CLI worksp...