diff --git a/.gitignore b/.gitignore index 32ea715..45cde45 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ .terraform.lock.hcl terraform.tfstate terraform.tfstate.backup +*.bak diff --git a/juju/home-maas/00-variables.tf b/juju/home-maas/00-variables.tf index b3d3f60..93a176a 100644 --- a/juju/home-maas/00-variables.tf +++ b/juju/home-maas/00-variables.tf @@ -1,3 +1,10 @@ +variable "machines" { + type = list(object({ + machine_id = number + constraints = string + })) +} + variable openstack-origin { type = string default = "distro" diff --git a/maas/arif-home/00-spaces.tf b/maas/arif-home/00-spaces.tf index e3de6b6..4ffaacd 100644 --- a/maas/arif-home/00-spaces.tf +++ b/maas/arif-home/00-spaces.tf @@ -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 } diff --git a/maas/arif-home/00-variables.tf b/maas/arif-home/00-variables.tf new file mode 100644 index 0000000..7e47cb4 --- /dev/null +++ b/maas/arif-home/00-variables.tf @@ -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 + })) + })) +} diff --git a/maas/arif-home/00-vlans.tf b/maas/arif-home/00-vlans.tf new file mode 100644 index 0000000..186a7f5 --- /dev/null +++ b/maas/arif-home/00-vlans.tf @@ -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 +} + diff --git a/maas/arif-home/terraform.tfvars b/maas/arif-home/terraform.tfvars new file mode 100644 index 0000000..21a9e80 --- /dev/null +++ b/maas/arif-home/terraform.tfvars @@ -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" + } + ] + } +]