What you will learn in this TP
- Describe OpenStack resources in Terraform
- Write tests with terraform test
- Simulate a provider with mock_provider
Introduction #
What you will learn in this section
- Describe OpenStack resources in Terraform
- Write tests with terraform test
- Simulate a provider with mock_provider
Context. The team wants to review and test every infrastructure change in CI before touching the production project.
Prerequisites: Docker, the AWS CLI (for the S3 API), kubectl, k3d and Terraform 1.7 or later; everything is simulated locally, with no OVHcloud account · Estimated time: 45 min
An automatically tested Terraform module, ready to apply on the Public Cloud.Hands-on #
Guided steps, with their solution.
1. Write the module
Why? The instance count variable and validations make the module reusable and safe.
Createmain.tfwith a network, a subnet, an HTTPS security group and N instances without public address.2. Validate
Why? fmt and validate catch syntax and type errors without a real provider.
Initialise, format and validate the module.3. Write tests with a mock provider
Why? mock_provider returns fake values: the module logic is tested without calling the OpenStack API.
Createtests/web.tftest.hclwith three tests: instance count, HTTPS rule and rejection of an invalid value.4. Run the tests
Why? These tests run in CI on every merge request, without cloud credentials.
Run the tests, then deliberately break a rule to see the failure.
Difficulty level : ●●●○○ (3/5)
My progress
Sign in to track your progress and take notes. Sign in
Recommended Articles
Exploiter OVHcloud : Terraform, supervision, sécurité, coûts et souveraineté
Exploiter OVHcloud en production : infrastructure as code avec les fournisseurs Terraform ovh et ...
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...
Le réseau Public Cloud OVHcloud : réseaux privés, vRack, Gateway, Floating IP et Load Balancer
Concevoir le réseau sur le Public Cloud OVHcloud : réseau public et réseaux privés OpenStack, vRa...
Le calcul sur OVHcloud : instances Public Cloud et Managed Kubernetes Service
Choisir et utiliser le calcul OVHcloud : gammes d'instances (General Purpose, CPU, RAM, GPU, Disc...
Terraform sur plusieurs clouds : AWS, Azure, Google Cloud, OVHcloud et Kubernetes
Utiliser Terraform avec les principaux fournisseurs : aws, azurerm, google, ovh et openstack, kub...
Comprendre OVHcloud : univers, régions, Public Cloud et outils
Découvrir OVHcloud, fournisseur de cloud européen : univers Bare Metal, Hosted Private Cloud, Pub...
Identités et accès sur OVHcloud : compte, IAM, utilisateurs OpenStack et clés
Sécuriser l'accès à OVHcloud : double authentification du compte, IAM OVHcloud (identités, politi...
Le stockage OVHcloud : Block Storage, Object Storage compatible S3 et Cold Archive
Stocker des données sur OVHcloud : volumes Block Storage (classique, haute performance), Object S...
Les bases de données managées OVHcloud (Public Cloud Databases)
Utiliser les bases de données managées du Public Cloud OVHcloud : PostgreSQL, MySQL, MongoDB, Val...