aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2024-09-24 21:30:22 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2024-09-24 21:30:22 +0200
commit48b0ac84061a2c73d08726ccabf4dd60c506aab3 (patch)
tree44c6d4fc7750db0aec3ec2e3457b0954c9e6b9fc
parent503ac9cad8bc348a31f23d2a721118eb1ce4653d (diff)
downloadinfra-48b0ac84061a2c73d08726ccabf4dd60c506aab3.tar.gz
infra-48b0ac84061a2c73d08726ccabf4dd60c506aab3.tar.bz2
infra-48b0ac84061a2c73d08726ccabf4dd60c506aab3.tar.xz
infra-48b0ac84061a2c73d08726ccabf4dd60c506aab3.zip
ipam-generate-tf
-rw-r--r--ansible/group_vars/all/ipam.yml6
-rw-r--r--ansible/plays/ipam-generate-tf.yml51
-rw-r--r--terraform/conflatorio-docker/main.tf16
-rw-r--r--terraform/ipam6/ipam6.tf150
4 files changed, 212 insertions, 11 deletions
diff --git a/ansible/group_vars/all/ipam.yml b/ansible/group_vars/all/ipam.yml
index 991bf81..452a79e 100644
--- a/ansible/group_vars/all/ipam.yml
+++ b/ansible/group_vars/all/ipam.yml
@@ -7,16 +7,14 @@
ipam6:
networks:
bitraf_dn42:
- range: "fdb1:4242:3538:::/48"
+ range: "fdb1:4242:3538::/48"
tnet_dn42:
range: "fdb1:4242:3538:2000::/52"
conflatorio_dn42:
description: Internal network on host
range: "fdb1:4242:3538:2001::/64"
hosts:
- conflatorio-ix: "fdb1:4242:3538:2001::ffff/64"
- conflatorio_docker:
- range: "fdb1:4242:3538:2001:1001::/112"
+ conflatorio: "fdb1:4242:3538:2001::ffff/64"
node1_dn42:
range: "fdb1:4242:3538:2002::/64"
node2_dn42:
diff --git a/ansible/plays/ipam-generate-tf.yml b/ansible/plays/ipam-generate-tf.yml
new file mode 100644
index 0000000..f905b51
--- /dev/null
+++ b/ansible/plays/ipam-generate-tf.yml
@@ -0,0 +1,51 @@
+- hosts: localhost
+ gather_facts: no
+ connection: local
+ tasks:
+ - name: Generate terraform/ipam6/ipam6.tf
+ register: tf
+ copy:
+ dest: ../../terraform/ipam6/ipam6.tf
+ content: |
+ output "networks" {
+ value = {
+ {% for name, network in ipam6.networks.items() %}
+ {% if not (network.range | ipv6) %}
+ Invalid network: {{ network.range }}
+ {% endif %}
+ {{ name }} = {
+ {% if network.description|default("") %}
+ description = "{{ network.description }}"
+ {% endif %}
+ range = "{{ network.range }}"
+ address = "{{ network.range|ipaddr("network") }}"
+ prefix = "{{ network.range|ipaddr("prefix") }}"
+ {% set hosts = network.hosts|default({}) %}
+ hosts = {
+ {% for name, addr in hosts.items() %}
+ {{ name }} = {
+ address: "{{ addr|ipaddr("address") }}"
+ prefix: "{{ addr|ipaddr("prefix") }}"
+ }
+ {% endfor %}
+ }
+ }
+ {% endfor %}
+ }
+ }
+
+ output "hosts" {
+ value = {
+ {% for name, network in ipam6.networks.items() %}
+ {% set hosts = network.hosts|default({}) %}
+ {% for name, addr in hosts.items() %}
+ {{ name }} = {
+ address: "{{ addr|ipaddr("address") }}"
+ prefix: "{{ addr|ipaddr("prefix") }}"
+ }
+ {% endfor %}
+ {% endfor %}
+ }
+ }
+ - shell: terraform fmt ../../terraform/ipam6/ipam6.tf
+ when: "tf.changed"
diff --git a/terraform/conflatorio-docker/main.tf b/terraform/conflatorio-docker/main.tf
index e7b11ad..ad4e6fd 100644
--- a/terraform/conflatorio-docker/main.tf
+++ b/terraform/conflatorio-docker/main.tf
@@ -23,13 +23,15 @@ data "sops_file_entry" "linode_token" {
}
locals {
- public_ip = "fdb1:4242:3538:2001::ffff"
- network_addr = "fdb1:4242:3538:2001:1001::"
- network_range = 112
- private_network_addr = "fdb1:4242:3538:2001:1002::"
- private_network_range = 112
+ hs = module.ipam6.hosts
+ ns = module.ipam6.networks
+ public_ip = local.hs.conflatorio-ix.address
+ network_addr = local.ns.conflatorio_docker.address
+ network_range = local.ns.conflatorio_docker.prefix
+ private_network_addr = local.ns.conflatorio_docker_private.address
+ private_network_range = local.ns.conflatorio_docker_private.range
}
-output "foo" {
- value = "foo!"
+module "ipam6" {
+ source = "../ipam6"
}
diff --git a/terraform/ipam6/ipam6.tf b/terraform/ipam6/ipam6.tf
new file mode 100644
index 0000000..88f8181
--- /dev/null
+++ b/terraform/ipam6/ipam6.tf
@@ -0,0 +1,150 @@
+output "networks" {
+ value = {
+ bitraf_dn42 = {
+ range = "fdb1:4242:3538::/48"
+ address = "fdb1:4242:3538::"
+ prefix = "48"
+ hosts = {
+ }
+ }
+ tnet_dn42 = {
+ range = "fdb1:4242:3538:2000::/52"
+ address = "fdb1:4242:3538:2000::"
+ prefix = "52"
+ hosts = {
+ }
+ }
+ conflatorio_dn42 = {
+ description = "Internal network on host"
+ range = "fdb1:4242:3538:2001::/64"
+ address = "fdb1:4242:3538:2001::"
+ prefix = "64"
+ hosts = {
+ conflatorio = {
+ address : "fdb1:4242:3538:2001::ffff"
+ prefix : "64"
+ }
+ }
+ }
+ node1_dn42 = {
+ range = "fdb1:4242:3538:2002::/64"
+ address = "fdb1:4242:3538:2002::"
+ prefix = "64"
+ hosts = {
+ }
+ }
+ node2_dn42 = {
+ range = "fdb1:4242:3538:2003::/64"
+ address = "fdb1:4242:3538:2003::"
+ prefix = "64"
+ hosts = {
+ }
+ }
+ knot_dn42 = {
+ range = "fdb1:4242:3538:2004::/64"
+ address = "fdb1:4242:3538:2004::"
+ prefix = "64"
+ hosts = {
+ knot = {
+ address : "fdb1:4242:3538:2004::ffff"
+ prefix : "64"
+ }
+ }
+ }
+ coregonus_dn42 = {
+ range = "fdb1:4242:3538:2005::/64"
+ address = "fdb1:4242:3538:2005::"
+ prefix = "64"
+ hosts = {
+ coregonus-ix = {
+ address : "fdb1:4242:3538:2005::ffff"
+ prefix : "64"
+ }
+ danneri = {
+ address : "fdb1:4242:3538:2005:9422:d355:95b7:f170"
+ prefix : "128"
+ }
+ }
+ }
+ coregonus_docker = {
+ range = "fdb1:4242:3538:2005:df01:676a:ec28:0a00/120"
+ address = "fdb1:4242:3538:2005:df01:676a:ec28:a00"
+ prefix = "120"
+ hosts = {
+ }
+ }
+ kv24_dn42 = {
+ range = "fdb1:4242:3538:2006::/64"
+ address = "fdb1:4242:3538:2006::"
+ prefix = "64"
+ hosts = {
+ kv24ix = {
+ address : "fdb1:4242:3538:2006::ffff"
+ prefix : "64"
+ }
+ }
+ }
+ conflatorio_dn42_2 = {
+ range = "fdb1:4242:3538:2007:1001::/112"
+ address = "fdb1:4242:3538:2007:1001::"
+ prefix = "112"
+ hosts = {
+ }
+ }
+ lhn2_dn42 = {
+ range = "fdb1:4242:3538:2008::/64"
+ address = "fdb1:4242:3538:2008::"
+ prefix = "64"
+ hosts = {
+ lhn2pi = {
+ address : "fdb1:4242:3538:2008::ffff"
+ prefix : "64"
+ }
+ conflatorio = {
+ address : "fdb1:4242:3538:2008:8042:32ff:fe0c:7161"
+ prefix : "128"
+ }
+ }
+ }
+ dn42 = {
+ range = "fd00::/8"
+ address = "fd00::"
+ prefix = "8"
+ hosts = {
+ }
+ }
+ }
+}
+
+output "hosts" {
+ value = {
+ conflatorio = {
+ address : "fdb1:4242:3538:2001::ffff"
+ prefix : "64"
+ }
+ knot = {
+ address : "fdb1:4242:3538:2004::ffff"
+ prefix : "64"
+ }
+ coregonus-ix = {
+ address : "fdb1:4242:3538:2005::ffff"
+ prefix : "64"
+ }
+ danneri = {
+ address : "fdb1:4242:3538:2005:9422:d355:95b7:f170"
+ prefix : "128"
+ }
+ kv24ix = {
+ address : "fdb1:4242:3538:2006::ffff"
+ prefix : "64"
+ }
+ lhn2pi = {
+ address : "fdb1:4242:3538:2008::ffff"
+ prefix : "64"
+ }
+ conflatorio = {
+ address : "fdb1:4242:3538:2008:8042:32ff:fe0c:7161"
+ prefix : "128"
+ }
+ }
+}