liveBook · Manning

Matrix strategy

As explained in Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu

A strategy matrix is a continuous-integration configuration that expands a job into multiple executions across specified parameter combinations.

A matrix strategy solves a practical CI problem: one workflow can validate the same Terraform code across multiple engines, versions, or tests without duplicating jobs. GitHub Actions expands each listed combination into an independent execution. section 7.7.3 section 9.3.6

A matrix names dimensions such as engine, version, experimental status, and test. GitHub Actions combines their values, while include adds selected combinations outside the default set. fail-fast: false lets all combinations finish, and continue-on-error can allow experimental combinations to fail without failing the workflow. section 7.7.3 section 9.3.6

Testing engines, versions, and individual tests

A Terratest workflow can define engine: ["opentofu", "terraform"], several supported versions, and test: [BasicTest, LambdaTest, ECSTest, Ec2Test]. Each test then runs independently for every selected engine and version. Conditional installation steps choose the matching OpenTofu or Terraform setup action, while an experimental version can use continue-on-error. section 9.3.6

Use matrix strategies to:

  • Check compatibility across OpenTofu and Terraform without locking a reusable module to one vendor or version. section 7.7.3
  • Split long-running infrastructure tests into parallel jobs instead of running examples sequentially. section 9.3.6
  • Pass a selected test or filter through a Makefile or test command so each matrix job targets one test. section 9.3.6 section 9.4.6
  • Keep version lists accurate: remove unsupported versions and distinguish stable combinations from explicitly experimental ones. section 7.7.3 section 9.4.6

How Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu covers it

How deep it goes
Defines dimensions, combinations, inclusions, conditional setup, failure behavior, and version caveats through operational workflow examples.
Examples
Uses engine-version compatibility checks, named Terratest functions, Terraform test filters, and long-running infrastructure examples.
What it assumes
Assumes GitHub Actions workflows and Terraform testing practices, while demonstrating engine selection and version handling.
What you can do after
Builds CI workflows that validate modules across supported engines, versions, tests, and experimental combinations.
How it connects
Connects GitHub Actions with continuous integration, OpenTofu, Terraform, Makefiles, Terratest, and Terraform testing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu. The section links point to the parts of the book it draws on.