Skip to content

razorsedge/terraform-ipv6-ula

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terraform IPv6 ULA Generator

This module makes it easy to generate an IPv6 unique local address (ULA) prefix. ULA are used for private addressing in IPv6 and are defined by RFC 4193. They have a 40-bit random part which makes them unique. This prefix will remain stable until the Terraform environment is destroyed.

Usage

module "ula" {
  source = "github.com/razorsedge/terraform-ipv6-ula"
}

resource "azurerm_resource_group" "this" {
  name     = "resource-group"
  location = "eastus"
}

resource "azurerm_virtual_network" "this" {
  name                = "network"
  address_space       = [module.ula.random_ula_network]
  location            = azurerm_resource_group.this.location
  resource_group_name = azurerm_resource_group.this.name
}

The value of module.ula.random_ula_network would be something like fda5:9f91:78b1::/48. The value would be different on each Terraform instantiation but would remain stable until tainted or destroyed. The subnet will always be a /48.

You can use cidrsubnet to make a smaller subnet from the base ULA.

resource "random_id" "subnet" {
  byte_length = 2
}

locals {
  # Creates a randomly generated /64 subnet from the /48 ULA prefix.
  ula_prefix_subnet = cidrsubnet(module.ula.random_ula_network, 16, random_id.subnet.hex)
}

output "subnet" {
  value = local.ula_prefix_subnet
}

Requirements

Name Version
terraform >= 1.0
random >= 2.2.1

Providers

Name Version
random 3.7.1

Modules

No modules.

Resources

Name Type
random_id.ula resource

Inputs

No inputs.

Outputs

Name Description
random_ula_network Randomly generated IPv6 ULA network prefix.