---
title: Terraform reference
description: Canonical makes open source secure, reliable and easy to use, providing
  support for Ubuntu and a portfolio of enterprise-grade technologies. Founded in
  2004, Canonical operates globally with team members in over 80 countries.
url: https://canonical-com-2934.demos.haus/maas/docs/reference-terraform?format=md
---

*Submit*

# Terraform reference

To use MAAS with [Terraform](https://www.terraform.io/), a [provider is available](https://github.com/maas/terraform-provider-maas). 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](https://www.terraform.io/intro) or various [available tutorials](https://learn.hashicorp.com/collections/terraform/aws-get-started).

## [API linkages](https://canonical-com-2934.demos.haus/maas/docs/reference-terraform?format=md#p-12784-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](https://canonical-com-2934.demos.haus/maas/docs/reference-terraform?format=md#p-12784-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*](https://canonical-com-2934.demos.haus/maas/docs/reference-terraform?format=md#p-12784-fabrics)

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

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

## [*Subnets*](https://canonical-com-2934.demos.haus/maas/docs/reference-terraform?format=md#p-12784-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*](https://canonical-com-2934.demos.haus/maas/docs/reference-terraform?format=md#p-12784-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](https://canonical-com-2934.demos.haus/maas/docs/reference-terraform?format=md#p-12784-resources)

For full details, refer to the [Terraform HCL documentation](https://www.terraform.io/language).

---

[Previous

Storage](https://canonical-com-2934.demos.haus/maas/docs/reference-maas-storage)
[Next

Troubleshooting](https://canonical-com-2934.demos.haus/maas/docs/maas-troubleshooting-guide)

Last updated 1 year, 5 months ago. [Help improve this document in the forum](https://discourse.maas.io/t/terraform-reference/6327).
