various updates

* Add the variabe definition of machines, which was in another file
* Add all the networking bits for MAAS
This commit is contained in:
Arif Ali 2024-01-02 18:18:39 +00:00
parent d3b8cb1800
commit 9c40b400cf
Signed by: arif
GPG Key ID: 369608FBA1353A70
6 changed files with 232 additions and 6 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
.terraform.lock.hcl
terraform.tfstate
terraform.tfstate.backup
*.bak

View File

@ -1,3 +1,10 @@
variable "machines" {
type = list(object({
machine_id = number
constraints = string
}))
}
variable openstack-origin {
type = string
default = "distro"

View File

@ -1,11 +1,11 @@
locals {
spaces = ["external","oam","ceph-access","ceph-replica","overlay","admin","internal"]
}
resource "maas_space" "maas_spaces" {
for_each = toset(local.spaces)
name = each.value
for_each = {
for index, spaces in var.spaces:
spaces.space => spaces
}
name = each.value.space
}

View File

@ -0,0 +1,15 @@
variable "spaces" {
type = list(object({
space = string
vid = number
cidr = string
mtu = number
managed = bool
ip_range = list(object({
type = string
start_ip = string
end_ip = string
comment = string
}))
}))
}

View File

@ -0,0 +1,56 @@
resource "maas_vlan" "maas_vlans" {
for_each = {
for index, spaces in var.spaces:
spaces.space => spaces
}
space = maas_space.maas_spaces[each.value.space].name
fabric = maas_fabric.fabric-0.id
vid=each.value.vid
}
locals {
ip_ranges = flatten([
for space_key, space in var.spaces : [
for ip_range_key, ip_range in space.ip_range : {
space_key = space.space
ip_range_key = ip_range_key
type = ip_range.type
start_ip = ip_range.start_ip
end_ip = ip_range.end_ip
comment = ip_range.comment
}
]
])
}
resource "maas_subnet" "maas_subnets" {
for_each = {
for index, spaces in var.spaces:
spaces.space => spaces
}
name = each.value.cidr
cidr = each.value.cidr
fabric = maas_fabric.fabric-0.id
vlan = maas_vlan.maas_vlans[each.value.space].vid
allow_dns = each.value.managed != false
}
resource "maas_subnet_ip_range" "dynamic_ip_ranges" {
for_each = {
for ip_range in local.ip_ranges:
"${ip_range.space_key}.${ip_range.ip_range_key}" => ip_range
}
subnet = maas_subnet.maas_subnets[each.value.space_key].id
type = each.value.type
start_ip = each.value.start_ip
end_ip = each.value.end_ip
comment = each.value.comment
}

View File

@ -0,0 +1,147 @@
spaces = [
{
space="external",
vid=1,
cidr="192.168.1.0/24",
mtu=1500,
managed=false
ip_range = [{
type = "reserved"
start_ip = "192.168.1.241"
end_ip = "192.168.1.254"
comment = "Servers"
}]
},
{
space="oam",
vid=300,
cidr="10.0.1.0/24",
mtu=1500,
managed=true,
ip_range = [
{
type = "dynamic"
start_ip = "10.0.1.1"
end_ip = "10.0.1.99"
comment = "Dynamic"
},
{
type = "reserved"
start_ip = "10.0.1.241"
end_ip = "10.0.1.254"
comment = "Servers"
},
{
type = "reserved"
start_ip = "10.0.1.211"
end_ip = "10.0.1.225"
comment = "OpenStack VIPs"
}
]
},
{
space="ceph-access",
vid=301,
cidr="10.0.2.0/24",
mtu=1500,
managed=true,
ip_range = [
{
type = "dynamic"
start_ip = "10.0.2.1"
end_ip = "10.0.2.99"
comment = "Dynamic"
},
{
type = "reserved"
start_ip = "10.0.2.241"
end_ip = "10.0.2.254"
comment = "Servers"
}
]
},
{
space="ceph-replica",
vid=302,
cidr="10.0.3.0/24",
mtu=1500,
managed=true,
ip_range = [
{
type = "dynamic"
start_ip = "10.0.3.1"
end_ip = "10.0.3.99"
comment = "Dynamic"
},
{
type = "reserved"
start_ip = "10.0.3.241"
end_ip = "10.0.3.254"
comment = "Servers"
}
]
},
{
space="overlay",
vid=303,
cidr="10.0.4.0/24",
mtu=1500,
managed=true,
ip_range = [
{
type = "dynamic"
start_ip = "10.0.4.1"
end_ip = "10.0.4.99"
comment = "Dynamic"
},
{
type = "reserved"
start_ip = "10.0.4.241"
end_ip = "10.0.4.254"
comment = "Servers"
}
]
},
{
space="admin",
vid=304,
cidr="10.0.5.0/24",
mtu=1500,
managed=true,
ip_range = [
{
type = "dynamic"
start_ip = "10.0.5.1"
end_ip = "10.0.5.99"
comment = "Dynamic"
},
{
type = "reserved"
start_ip = "10.0.5.241"
end_ip = "10.0.5.254"
comment = "Servers"
}
]
},
{
space="internal",
vid=305,
cidr="10.0.6.0/24",
mtu=1500,
managed=true,
ip_range = [
{
type = "dynamic"
start_ip = "10.0.6.1"
end_ip = "10.0.6.99"
comment = "Dynamic"
},
{
type = "reserved"
start_ip = "10.0.6.241"
end_ip = "10.0.6.254"
comment = "Servers"
}
]
}
]