RousselTMLEARNING

TP · OVHcloud: from discovery to expertise

Lab: Terraform for OVHcloud tested with mock providers

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. 1. Write the module

    Why? The instance count variable and validations make the module reusable and safe.

    Create main.tf with a network, a subnet, an HTTPS security group and N instances without public address.
  2. 2. Validate

    Why? fmt and validate catch syntax and type errors without a real provider.

    Initialise, format and validate the module.
  3. 3. Write tests with a mock provider

    Why? mock_provider returns fake values: the module logic is tested without calling the OpenStack API.

    Create tests/web.tftest.hcl with three tests: instance count, HTTPS rule and rejection of an invalid value.
  4. 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

  • ⏱ Estimated time : ≈ 45 min

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

💬 Ask a question

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...

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!