From e5800cf58852bb1811d4f6ec1439d5742fcbe24e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=CC=81lvaro=20Curto=20Merino?= Date: Tue, 17 Sep 2024 11:06:36 +0200 Subject: [PATCH 1/2] tn_init bastion can modify its networks again --- ocf/code/component_playbook.yaml | 2 +- tn_bastion/code/one/iac/tn_bastion.tf.j2 | 9 ++++----- tn_bastion/variables/one/private.yaml | 2 -- tn_init/code/one/iac/tn_bastion.tf.j2 | 4 +++- tn_init/variables/one/private.yaml | 3 +++ tn_vxlan/sample_input_file.yaml | 7 ++++++- 6 files changed, 17 insertions(+), 10 deletions(-) diff --git a/ocf/code/component_playbook.yaml b/ocf/code/component_playbook.yaml index b6719cd1..78fe21d9 100644 --- a/ocf/code/component_playbook.yaml +++ b/ocf/code/component_playbook.yaml @@ -2,7 +2,7 @@ - name: "STAGE 1: Prepare to access a previous target component" hosts: localhost gather_facts: false - connection: local + connection: local tasks: - name: Load enviromental variables from different sources ansible.builtin.include_tasks: "{{ workspace }}/.global/cac/load_variables.yaml" diff --git a/tn_bastion/code/one/iac/tn_bastion.tf.j2 b/tn_bastion/code/one/iac/tn_bastion.tf.j2 index abaf32f1..06bbb814 100644 --- a/tn_bastion/code/one/iac/tn_bastion.tf.j2 +++ b/tn_bastion/code/one/iac/tn_bastion.tf.j2 @@ -1,7 +1,7 @@ # https://registry.terraform.io/providers/OpenNebula/opennebula/latest/docs/resources/virtual_machine # https://docs.opennebula.io/6.8/management_and_operations/references/template.html#context-section -resource "opennebula_virtual_machine" "{{ entity_name }}" { - name = "{{ tn_id }}-{{ entity_name }}" +resource "opennebula_virtual_machine" "tn_bastion" { + name = "{{ tn_id }}-tn_bastion" template_id = {{ site_available_components.tn_bastion.template_id }} cpu = {{ one_bastion_cpu }} vcpu = {{ one_bastion_cpu }} @@ -23,7 +23,6 @@ resource "opennebula_virtual_machine" "{{ entity_name }}" { driver = "qcow2" } #} - nic { model = "virtio" network_id = "{{ site_networks_id.default }}" @@ -38,12 +37,12 @@ resource "opennebula_virtual_machine" "{{ entity_name }}" { depends_on = [ opennebula_virtual_network_address_range.tn_vxlan ] } -output "{{ entity_name }}-id" { +output "tn_bastion-id" { description = "OpenNebula VM ID" value = opennebula_virtual_machine.{{ entity_name }}.id } -output "{{ entity_name }}-ips" { +output "tn_bastion-ips" { description = "OpenNebula VM Network Assignments" value = { for nic in opennebula_virtual_machine.{{ entity_name }}.nic[*] : nic.network_id => nic.computed_ip } } diff --git a/tn_bastion/variables/one/private.yaml b/tn_bastion/variables/one/private.yaml index 65b78aac..2ef6fa97 100644 --- a/tn_bastion/variables/one/private.yaml +++ b/tn_bastion/variables/one/private.yaml @@ -14,7 +14,5 @@ one_bastion_disk: 10240 # Size of the Image. Future plans to downsize it one_bastion_wireguard_allowedips: "192.168.199.0/24" -# By default, In tn_bastion the first VNet is hardcoded to be the site default (site_networks_id.default) -# The following ones are appended here (tn_vxlan.id) one_bastion_networks: - tn_vxlan diff --git a/tn_init/code/one/iac/tn_bastion.tf.j2 b/tn_init/code/one/iac/tn_bastion.tf.j2 index a7a59648..d1961e0a 100644 --- a/tn_init/code/one/iac/tn_bastion.tf.j2 +++ b/tn_init/code/one/iac/tn_bastion.tf.j2 @@ -27,10 +27,12 @@ resource "opennebula_virtual_machine" "tn_bastion" { model = "virtio" network_id = "{{ site_networks_id.default }}" } +{% for network in one_bastion_networks %} nic { model = "virtio" - network_id = opennebula_virtual_network.tn_vxlan.id + network_id = opennebula_virtual_network.{{ network }}.id } +{% endfor %} depends_on = [ opennebula_virtual_network_address_range.tn_vxlan ] } diff --git a/tn_init/variables/one/private.yaml b/tn_init/variables/one/private.yaml index 4ad8d9f6..5554d36a 100644 --- a/tn_init/variables/one/private.yaml +++ b/tn_init/variables/one/private.yaml @@ -34,3 +34,6 @@ one_bastion_memory: 1024 one_bastion_disk: 10240 # Size of the Image. Future plans to downsize it one_bastion_wireguard_allowedips: "192.168.199.0/24" + +one_bastion_networks: + - tn_vxlan diff --git a/tn_vxlan/sample_input_file.yaml b/tn_vxlan/sample_input_file.yaml index 8fe88148..050d412f 100644 --- a/tn_vxlan/sample_input_file.yaml +++ b/tn_vxlan/sample_input_file.yaml @@ -1,3 +1,8 @@ # THIS IS AN INPUT FILE EXAMPLE. Values may not be valid for your enviroment - # This component does not need any input file + +#one_vxlan_gw: "192.168.199.1" +#one_vxlan_netmask: "255.255.255.0" +#one_vxlan_dns: "1.1.1.1 1.0.0.1" +#one_vxlan_first_ip: "192.168.199.1" +#one_vxlan_address_size: 254 From 340a885a45f3f897c5513782c41c64f508dcd828 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=CC=81lvaro=20Curto=20Merino?= Date: Tue, 17 Sep 2024 11:44:39 +0200 Subject: [PATCH 2/2] Reunify IaC between tn_init and tn_bastion and tn_vxlan --- tn_bastion/code/one/iac/tn_bastion.tf.j2 | 4 ++-- tn_vxlan/code/one/iac/tn_vxlan.tf.j2 | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tn_bastion/code/one/iac/tn_bastion.tf.j2 b/tn_bastion/code/one/iac/tn_bastion.tf.j2 index 06bbb814..d1961e0a 100644 --- a/tn_bastion/code/one/iac/tn_bastion.tf.j2 +++ b/tn_bastion/code/one/iac/tn_bastion.tf.j2 @@ -39,10 +39,10 @@ resource "opennebula_virtual_machine" "tn_bastion" { output "tn_bastion-id" { description = "OpenNebula VM ID" - value = opennebula_virtual_machine.{{ entity_name }}.id + value = opennebula_virtual_machine.tn_bastion.id } output "tn_bastion-ips" { description = "OpenNebula VM Network Assignments" - value = { for nic in opennebula_virtual_machine.{{ entity_name }}.nic[*] : nic.network_id => nic.computed_ip } + value = { for nic in opennebula_virtual_machine.tn_bastion.nic[*] : nic.network_id => nic.computed_ip } } diff --git a/tn_vxlan/code/one/iac/tn_vxlan.tf.j2 b/tn_vxlan/code/one/iac/tn_vxlan.tf.j2 index 83a79d60..2a5bdec9 100644 --- a/tn_vxlan/code/one/iac/tn_vxlan.tf.j2 +++ b/tn_vxlan/code/one/iac/tn_vxlan.tf.j2 @@ -1,6 +1,6 @@ # https://registry.terraform.io/providers/OpenNebula/opennebula/latest/docs/resources/virtual_network -resource "opennebula_virtual_network" "{{ entity_name }}" { - name = "{{ tn_id }}-{{ entity_name }}" +resource "opennebula_virtual_network" "tn_vxlan" { + name = "{{ tn_id }}-tn_vxlan" physical_device = "{{ one_vxlan_physical_device }}" cluster_ids = {{ site_clusters }} type = "vxlan" @@ -13,14 +13,14 @@ resource "opennebula_virtual_network" "{{ entity_name }}" { dns = "{{ one_vxlan_dns }}" } -resource "opennebula_virtual_network_address_range" "{{ entity_name }}" { - virtual_network_id = opennebula_virtual_network.{{ entity_name }}.id +resource "opennebula_virtual_network_address_range" "tn_vxlan" { + virtual_network_id = opennebula_virtual_network.tn_vxlan.id ar_type = "IP4" ip4 = "{{ one_vxlan_first_ip }}" size = {{ one_vxlan_address_size }} } -output "{{ entity_name }}-id" { +output "tn_vxlan-id" { description = "OpenNebula Network ID" - value = opennebula_virtual_network.{{ entity_name }}.id + value = opennebula_virtual_network.tn_vxlan.id }