If you wish to use MAAS with Terraform↗
, we have made a provider available↗
. This article provides reference information about the data sources and resources that can be accessed via this provider. It does not attempt to explain the mechanics or usage of Terraform or offer any tutorial information related to this MAAS Terraform provider.
The MAAS provider is a Terraform provider that allows you to manage MAAS resources using the Terraform (CRUD) tool. This provider can be used to manage many aspects of a MAAS environment, including networking, users, machines, and VM hosts.
These aspects can be divided into three categories of Terraform-compliant HCL:
We will deal with each of these categories in turn. For each data source and resource, we will offer a brief definition and description of how that item is employed in MAAS. If you are new to Terraform↗
, or want to explore what terraforming may provide for your MAAS instance, you may wish to consult the Terraform documentation↗
or one of the many tutorials available↗
.
The schema that provides an API linkage to MAAS from Terraform consists of a standard HCL provider block and a provider API block. As with all Terraform providers, the provider block contains at least two items:
The provider block would look something like this:
terraform {
required_providers {
maas = {
source = "maas/maas"
version = "~>1.0"
}
}
}
The provider API block contains the necessary credentials to allow Terraform to access your MAAS instance, which include three things:
A typical provider API block might look like this:
provider "maas" {
api_version = "2.0"
api_key = "<YOUR API KEY>"
api_url = "http://127.0.0.1:5240/MAAS"
}
A completed definition would also include some data sources and resources, like this typical example:
terraform {
required_providers {
maas = {
source = "maas/maas"
version = "~>1.0"
}
}
}
provider "maas" {
api_version = "2.0"
api_key = "<YOUR API KEY>"
api_url = "<YOUR API URL>"
}
resource "maas_space" "tf_space" {
name = "tf-space"
}
resource "maas_fabric" "tf_fabric" {
name = "tf-fabric"
}
resource "maas_vlan" "tf_vlan" {
fabric = maas_fabric.tf_fabric.id
vid = 14
name = "tf-vlan14"
space = maas_space.tf_space.name
}
resource "maas_subnet" "tf_subnet" {
cidr = "10.88.88.0/24"
fabric = maas_fabric.tf_fabric.id
vlan = maas_vlan.tf_vlan.vid
name = "tf_subnet"
gateway_ip = "10.88.88.1"
dns_servers = [
"1.1.1.1",
]
ip_ranges {
type = "reserved"
start_ip = "10.88.88.1"
end_ip = "10.88.88.50"
}
ip_ranges {
type = "dynamic"
start_ip = "10.88.88.200"
end_ip = "10.88.88.254"
}
}
See the Terraform HCL documentation↗
for more details about these blocks.
The MAAS Terraform provider offers three data sources, all representing network elements:
↗
, which is essentially a VLAN namespace – that is, it connects two or more VLANs together.↗
, which is the traditional way of dividing up IP addresses into smaller networks, e.g., 192.168.15.0/24.↗
, a “virtual LAN”, which is a collection of specific addresses or ports that are connected together to form a restricted network.Each of these data sources has a specific HCL block with elements structured appropriately to manage that MAAS element.
The fabric↗
data source provides minimal details, namely, the fabric ID, of an existing MAAS fabric. It takes one argument (the fabric name) and exports one attribute (the fabric ID):
data "maas_fabric" "default" {
name = "maas"
}
Fabrics within MAAS are not widely manipulated in and of themselves, but rather serve as containers for storing VLAN/subnet combinations.
The subnet↗
data source provides a number of details about an existing MAAS network subnet. The element takes one argument, the subnet CIDR, and exports a number of attributes:
Declaring a subnet looks something like this example:
data "maas_subnet" "vid10" {
cidr = "10.10.0.0/16"
}
Subnets are the network backbone of MAAS, and thus provide a number of attributes that can be manipulated to alter the behaviour of MAAS.
The VLAN↗
data source provides details about an existing MAAS VLAN. A VLAN takes two arguments:
A VLAN data source exports a few useful attributes:
VLAN spaces↗
are used mostly by Juju, but can be employed by other tools, if desired.
The typical definition of a MAAS VLAN in HCL might look like this:
data "maas_vlan" "vid10" {
fabric = data.maas_fabric.default.id
vlan = 10
}
VLANs are available as data sources, but generally, subnets are the workhorses of most MAAS instances.
The MAAS Terraform provider makes a large number of resources available, currently including the following items. Because of the large number of items, details of arguments and attributes are not duplicated here, but instead provided from a single source at the given links:
↗
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.↗
provides a resource to manage MAAS VM hosts. Note that MAAS VM hosts are not machines, but the host(s) upon which virtual machines are created.↗
provides a resource to manage MAAS VM host machines, which represent the individual machines that are spun up on a given VM host.↗
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.↗
provides a resource to manage a physical network interface from an existing MAAS machine. Network interfaces can be created and deleted at will via the MAAS CLI/UI, so there may be more than one of these associate with any given machine.↗
provides a resource to manage network configuration on a network interface. Note that this does not represent the interface itself, but the parameter set that configure that interface.↗
provides a resource to manage MAAS network fabrics, which are described above↗
. ↗
provides a resource to manage MAAS network VLANs, also described above↗
.↗
provides a resource to manage MAAS network subnets, also described above↗
↗
provides a resource to manage MAAS network subnets IP ranges. IP ranges carry particular importance when managing DHCP with multiple DHCP servers, for example.↗
provides a resource to manage MAAS DNS domains.↗
provides a resource to manage MAAS DNS domain records.↗
provides a resource to manage MAAS network spaces↗
.↗
provides a resource to manage block devices on MAAS machines.↗
provides a resource to manage a MAAS tag. MAAS tags have multiple roles in controlling how machines are configured, booted, and monitored.↗
provides a resource to manage MAAS users. This resource does not provide any control over any Candid or RBAC restrictions that may be in place.Please visit the links to get details on these resources, since the documentation at those links will always be the most current information available.