MAAS Infrastructure as Code
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. It focuses on:
Each section provides definitions and usage examples. For more about Terraform, consult the Terraform documentation or various available tutorials.
To connect MAAS with Terraform, you'll need both a standard HCL provider block and a provider API block. The former requires at least:
source
element: "maas/maas".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:
Example:
provider "maas" {
api_version = "2.0"
api_key = "<YOUR API KEY>"
api_url = "http://127.0.0.1:5240/MAAS"
}
The MAAS Terraform provider offers three main data sources focused on networking:
Each data source comes with an HCL block that manages its corresponding MAAS element.
The fabric
data source reveals minimal details, usually the fabric ID:
data "maas_fabric" "default" {
name = "maas"
}
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"
}
The VLAN
data source focuses on an existing MAAS VLAN. For instance:
data "maas_vlan" "vid10" {
fabric = data.maas_fabric.default.id
vlan = 10
}
The MAAS Terraform provider avails a plethora of resources. Given their number, this guide doesn't cover arguments and attributes in detail. You can explore individual resources like maas_instance
, maas_vm_host
, maas_vm_host_machine
, and maas_machine
via their documentation links.
For full details, refer to the Terraform HCL documentation^.