Integrating with Terraform for IAC

Errors or typos? Topics missing? Hard to read? Let us know.

To use MAAS with Terraform, a provider is available. This guide gives an overview of data sources and resources accessible via this provider, without delving into the mechanics of Terraform or the MAAS Terraform provider.

The MAAS Terraform provider enables management of MAAS resources via Terraform’s CRUD tool. Each section in this document provides definitions and usage examples. For more about Terraform, consult the Terraform documentation or various available tutorials.

API linkages

To connect MAAS with Terraform, you’ll need both a standard HCL provider block and a provider API block. The former requires at least:

  • A source element: “maas/maas”.
  • A version element: “~>1.0”.

Here’s what the provider block might look like:

terraform {
  required_providers {
    maas = {
      source  = "maas/maas"
      version = "~>1.0"
    }
  }
}

The provider API block includes credentials for MAAS access:

  • API version
  • API key
  • API URL

Example:

provider "maas" {
  api_version = "2.0"
  api_key = "<YOUR API KEY>"
  api_url = "http://127.0.0.1:5240/MAAS"
}

Data sources

The MAAS Terraform provider offers three main data sources focused on networking:

  • Fabrics
  • Subnets
  • VLANs

Each data source comes with an HCL block that manages its corresponding MAAS element.

Fabrics

The fabric data source reveals minimal details, usually the fabric ID:

data "maas_fabric" "default" {
  name = "maas"
}

Subnets

The subnet data source provides extensive attributes for an existing MAAS subnet. To declare one:

data "maas_subnet" "vid10" {
  cidr = "10.10.0.0/16"
}

VLANs

The VLAN data source focuses on an existing MAAS VLAN. For instance:

data "maas_vlan" "vid10" {
  fabric = data.maas_fabric.default.id
  vlan = 10
}

Resources

For full details, refer to the Terraform HCL documentation^.

Those links are 404 by now unfortunately.

How do we use terraform to create bonds? Or is it not implemented yet?

I don’t see maas in the TF provider list…Is the documentation correct?

any update on formally publishing this provider in the hashicorp registry?

the maas provider is a critical part of the workflow we’re building, and it would be very helpful to treat it as such.

Trying with terraform but failing in deployment of machines

Hi @vinodsiraparapu

According to your post you are using incorrect resources for machine deployment. You should use maas_instance Instead of maas_machine.

Please note the difference:

  • maas_machine provides a resource to manage MAAS machines; note that these are typically physical machines (rather than VMs), so they tend to respond differently at times.

  • maas_instance provides a resource to deploy and release machines already configured in MAAS, based on the specified parameters. If no parameters are given, a random machine will be allocated and deployed using the defaults.