diff options
author | 2024-02-13 13:01:54 +0100 | |
---|---|---|
committer | 2024-02-13 13:03:23 +0000 | |
commit | e664d6963984e33a0efab939d83fd0f015f80fbb (patch) | |
tree | 7623cb8e7066ddb7038d291242bcc65c4161d149 /fdio.infra.terraform/terraform-openstack-2n/main.tf | |
parent | 3797578ec4b0c4662afa44e7556d13d19e2c8e30 (diff) |
feat(bootstrap): Add ability to load external NODE_FLAVOR
Signed-off-by: Peter Mikus <peter.mikus@protonmail.ch>
Change-Id: Ia6e07111af543280b2365840bced02f94cf91e75
Diffstat (limited to 'fdio.infra.terraform/terraform-openstack-2n/main.tf')
-rw-r--r-- | fdio.infra.terraform/terraform-openstack-2n/main.tf | 211 |
1 files changed, 211 insertions, 0 deletions
diff --git a/fdio.infra.terraform/terraform-openstack-2n/main.tf b/fdio.infra.terraform/terraform-openstack-2n/main.tf new file mode 100644 index 0000000000..f306933a81 --- /dev/null +++ b/fdio.infra.terraform/terraform-openstack-2n/main.tf @@ -0,0 +1,211 @@ +locals { + image_name = "Ubuntu 22.04.2 LTS" + image_source_url = "http://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img" + resource_prefix = "csit-2n" + testbed_name = "xu6n" + topology_name = "2n" +} + +# Create Cloud-Init config for TG. +data "template_cloudinit_config" "cloudinit_config_tg1" { + gzip = false + base64_encode = false + + part { + content_type = "text/cloud-config" + content = templatefile( + "${path.module}/user-data-tg1", {} + ) + } +} + +# Create Cloud-Init config for SUT1. +data "template_cloudinit_config" "cloudinit_config_sut1" { + gzip = false + base64_encode = false + + part { + content_type = "text/cloud-config" + content = templatefile( + "${path.module}/user-data-sut1", {} + ) + } +} + +# Create OpenStack Image. +module "openstack_images_image_v2" { + source = "pmikus/images-image-v2/openstack" + version = "1.54.1" + + image_source_url = local.image_source_url + name = local.image_name +} + +# Create OpenStack Keypair. +module "openstack_compute_keypair_v2" { + source = "pmikus/compute-keypair-v2/openstack" + version = "1.54.1" + + name = "${local.resource_prefix}-keypair" +} + + +# Create management port in dedicated subnet. +resource "openstack_networking_port_v2" "port_tg1_mgmt" { + admin_state_up = true + fixed_ip { + ip_address = "10.21.152.2" + subnet_id = "b1f9573d-4c2e-45da-bbac-cb3f191ab0f5" + } + name = "${local.resource_prefix}-tg1-mgmt-port" + network_id = var.network_id_mgmt + port_security_enabled = false + + binding { + vnic_type = "normal" + } +} + +# Create data port in dedicated subnet. +resource "openstack_networking_port_v2" "port_tg1_data1" { + admin_state_up = false + name = "${local.resource_prefix}-tg1-data1-port" + network_id = var.network_id_data + port_security_enabled = false + + binding { + vnic_type = "direct" + } +} + +# Create data port in dedicated subnet. +resource "openstack_networking_port_v2" "port_tg1_data2" { + admin_state_up = false + name = "${local.resource_prefix}-tg1-data2-port" + network_id = var.network_id_data + port_security_enabled = false + + binding { + vnic_type = "direct" + } +} + +# Create TG instance. +module "tg1" { + depends_on = [ + module.openstack_compute_keypair_v2, + module.openstack_images_image_v2 + ] + + source = "pmikus/compute-instance-v2/openstack" + version = "1.54.1" + + flavour_name = var.flavour_name + image_id = module.openstack_images_image_v2.id + key_pair = module.openstack_compute_keypair_v2.name + name = "${local.resource_prefix}-tg1" + networks = { + "platform-shared-port" = openstack_networking_port_v2.port_tg1_mgmt.id + "data-playground-port1" = openstack_networking_port_v2.port_tg1_data1.id + "data-playground-port2" = openstack_networking_port_v2.port_tg1_data2.id + } + user_data = data.template_cloudinit_config.cloudinit_config_tg1.rendered +} + +# Create management port in dedicated subnet. +resource "openstack_networking_port_v2" "port_sut1_mgmt" { + admin_state_up = true + fixed_ip { + ip_address = "10.21.152.3" + subnet_id = "b1f9573d-4c2e-45da-bbac-cb3f191ab0f5" + } + name = "${local.resource_prefix}-sut1-mgmt-port" + network_id = var.network_id_mgmt + port_security_enabled = false + + binding { + vnic_type = "normal" + } +} + +# Create data port in dedicated subnet. +resource "openstack_networking_port_v2" "port_sut1_data1" { + admin_state_up = false + name = "${local.resource_prefix}-sut1-data1-port" + network_id = var.network_id_data + port_security_enabled = false + + binding { + vnic_type = "direct" + } +} + +# Create data port in dedicated subnet. +resource "openstack_networking_port_v2" "port_sut1_data2" { + admin_state_up = false + name = "${local.resource_prefix}-sut1-data2-port" + network_id = var.network_id_data + port_security_enabled = false + + binding { + vnic_type = "direct" + } +} + +# Create SUT instance. +module "sut1" { + depends_on = [ + module.openstack_compute_keypair_v2, + module.openstack_images_image_v2 + ] + + source = "pmikus/compute-instance-v2/openstack" + version = "1.54.1" + + flavour_name = var.flavour_name + image_id = module.openstack_images_image_v2.id + key_pair = module.openstack_compute_keypair_v2.name + name = "${local.resource_prefix}-sut1" + networks = { + "platform-shared-port" = openstack_networking_port_v2.port_sut1_mgmt.id + "data-playground-port1" = openstack_networking_port_v2.port_sut1_data1.id + "data-playground-port2" = openstack_networking_port_v2.port_sut1_data2.id + } + user_data = data.template_cloudinit_config.cloudinit_config_sut1.rendered +} + +resource "local_file" "topology_file" { + depends_on = [ + module.tg1, + module.sut1 + ] + + content = templatefile( + "${path.module}/topology-${local.topology_name}.tftpl", + { + tg_if1_mac = openstack_networking_port_v2.port_tg1_data1.mac_address + tg_if2_mac = openstack_networking_port_v2.port_tg1_data2.mac_address + dut1_if1_mac = openstack_networking_port_v2.port_sut1_data1.mac_address + dut1_if2_mac = openstack_networking_port_v2.port_sut1_data2.mac_address + tg_public_ip = openstack_networking_port_v2.port_tg1_mgmt.fixed_ip[0].ip_address + dut1_public_ip = openstack_networking_port_v2.port_sut1_mgmt.fixed_ip[0].ip_address + } + ) + filename = "${path.module}/${local.topology_name}-x-${local.testbed_name}.yaml" +} + +resource "local_file" "hosts" { + depends_on = [ + module.tg1, + module.sut1 + ] + + content = templatefile( + "${path.module}/hosts.tftpl", + { + tg_public_ip = openstack_networking_port_v2.port_tg1_mgmt.fixed_ip[0].ip_address + dut1_public_ip = openstack_networking_port_v2.port_sut1_mgmt.fixed_ip[0].ip_address + } + ) + filename = "${path.module}/hosts.yaml" +} |