aboutsummaryrefslogtreecommitdiffstats
path: root/fdio.infra.terraform/terraform-openstack-2n
diff options
context:
space:
mode:
authorpmikus <peter.mikus@protonmail.ch>2024-02-13 13:01:54 +0100
committerpmikus <peter.mikus@protonmail.ch>2024-02-13 13:03:23 +0000
commite664d6963984e33a0efab939d83fd0f015f80fbb (patch)
tree7623cb8e7066ddb7038d291242bcc65c4161d149 /fdio.infra.terraform/terraform-openstack-2n
parent3797578ec4b0c4662afa44e7556d13d19e2c8e30 (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')
-rw-r--r--fdio.infra.terraform/terraform-openstack-2n/README.md58
-rw-r--r--fdio.infra.terraform/terraform-openstack-2n/hosts.tftpl8
-rw-r--r--fdio.infra.terraform/terraform-openstack-2n/main.tf211
-rw-r--r--fdio.infra.terraform/terraform-openstack-2n/outputs.tf9
-rw-r--r--fdio.infra.terraform/terraform-openstack-2n/topology-2n.tftpl59
-rw-r--r--fdio.infra.terraform/terraform-openstack-2n/user-data-sut166
-rw-r--r--fdio.infra.terraform/terraform-openstack-2n/user-data-tg171
-rw-r--r--fdio.infra.terraform/terraform-openstack-2n/variables.tf14
-rw-r--r--fdio.infra.terraform/terraform-openstack-2n/versions.tf9
9 files changed, 505 insertions, 0 deletions
diff --git a/fdio.infra.terraform/terraform-openstack-2n/README.md b/fdio.infra.terraform/terraform-openstack-2n/README.md
new file mode 100644
index 0000000000..3ddb0f3789
--- /dev/null
+++ b/fdio.infra.terraform/terraform-openstack-2n/README.md
@@ -0,0 +1,58 @@
+# terraform-openstack-2n-generic
+Terraform module to create 2n-generic topology.
+
+<!-- BEGIN_TF_DOCS -->
+## Requirements
+
+| Name | Version |
+|------|---------|
+| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.4.2 |
+| <a name="requirement_openstack"></a> [openstack](#requirement\_openstack) | ~> 1.53.0 |
+
+## Providers
+
+| Name | Version |
+|------|---------|
+| <a name="provider_local"></a> [local](#provider\_local) | 2.4.1 |
+| <a name="provider_openstack"></a> [openstack](#provider\_openstack) | 1.53.0 |
+| <a name="provider_template"></a> [template](#provider\_template) | 2.2.0 |
+
+## Modules
+
+| Name | Source | Version |
+|------|--------|---------|
+| <a name="module_openstack_compute_keypair_v2"></a> [openstack\_compute\_keypair\_v2](#module\_openstack\_compute\_keypair\_v2) | pmikus/compute-keypair-v2/openstack | 1.54.1 |
+| <a name="module_openstack_images_image_v2"></a> [openstack\_images\_image\_v2](#module\_openstack\_images\_image\_v2) | pmikus/images-image-v2/openstack | 1.54.1 |
+| <a name="module_sut1"></a> [sut1](#module\_sut1) | pmikus/compute-instance-v2/openstack | 1.54.1 |
+| <a name="module_tg1"></a> [tg1](#module\_tg1) | pmikus/compute-instance-v2/openstack | 1.54.1 |
+
+## Resources
+
+| Name | Type |
+|------|------|
+| [local_file.hosts](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
+| [local_file.topology_file](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
+| [openstack_networking_port_v2.port_sut1_data1](https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs/resources/networking_port_v2) | resource |
+| [openstack_networking_port_v2.port_sut1_data2](https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs/resources/networking_port_v2) | resource |
+| [openstack_networking_port_v2.port_sut1_mgmt](https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs/resources/networking_port_v2) | resource |
+| [openstack_networking_port_v2.port_tg1_data1](https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs/resources/networking_port_v2) | resource |
+| [openstack_networking_port_v2.port_tg1_data2](https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs/resources/networking_port_v2) | resource |
+| [openstack_networking_port_v2.port_tg1_mgmt](https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs/resources/networking_port_v2) | resource |
+| [template_cloudinit_config.cloudinit_config_sut1](https://registry.terraform.io/providers/hashicorp/template/latest/docs/data-sources/cloudinit_config) | data source |
+| [template_cloudinit_config.cloudinit_config_tg1](https://registry.terraform.io/providers/hashicorp/template/latest/docs/data-sources/cloudinit_config) | data source |
+
+## Inputs
+
+| Name | Description | Type | Default | Required |
+|------|-------------|------|---------|:--------:|
+| <a name="input_flavour_name"></a> [flavour\_name](#input\_flavour\_name) | (Optional; Required if flavor\_id is empty) The name of the desired flavor for the server. Changing this resizes the existing server. | `string` | n/a | yes |
+| <a name="input_network_id_data"></a> [network\_id\_data](#input\_network\_id\_data) | (Required) The ID of the network to attach the port to. Changing this creates a new port. | `string` | n/a | yes |
+| <a name="input_network_id_mgmt"></a> [network\_id\_mgmt](#input\_network\_id\_mgmt) | (Required) The ID of the network to attach the port to. Changing this creates a new port. | `string` | n/a | yes |
+
+## Outputs
+
+| Name | Description |
+|------|-------------|
+| <a name="output_sut_id"></a> [sut\_id](#output\_sut\_id) | SUT VM ID. |
+| <a name="output_tg_id"></a> [tg\_id](#output\_tg\_id) | TG VM ID. |
+<!-- END_TF_DOCS -->
diff --git a/fdio.infra.terraform/terraform-openstack-2n/hosts.tftpl b/fdio.infra.terraform/terraform-openstack-2n/hosts.tftpl
new file mode 100644
index 0000000000..cb36dbb138
--- /dev/null
+++ b/fdio.infra.terraform/terraform-openstack-2n/hosts.tftpl
@@ -0,0 +1,8 @@
+all:
+ children:
+ tg:
+ hosts:
+ ${tg_public_ip}
+ sut:
+ hosts:
+ ${dut1_public_ip} \ No newline at end of file
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"
+}
diff --git a/fdio.infra.terraform/terraform-openstack-2n/outputs.tf b/fdio.infra.terraform/terraform-openstack-2n/outputs.tf
new file mode 100644
index 0000000000..f8985685f0
--- /dev/null
+++ b/fdio.infra.terraform/terraform-openstack-2n/outputs.tf
@@ -0,0 +1,9 @@
+output "tg_id" {
+ description = "TG VM ID."
+ value = module.tg1.id
+}
+
+output "sut_id" {
+ description = "SUT VM ID."
+ value = module.sut1.id
+} \ No newline at end of file
diff --git a/fdio.infra.terraform/terraform-openstack-2n/topology-2n.tftpl b/fdio.infra.terraform/terraform-openstack-2n/topology-2n.tftpl
new file mode 100644
index 0000000000..1129a6f8f3
--- /dev/null
+++ b/fdio.infra.terraform/terraform-openstack-2n/topology-2n.tftpl
@@ -0,0 +1,59 @@
+---
+metadata:
+ version: 0.1
+ schema:
+ - resources/topology_schemas/2_node_topology.sch.yaml
+ - resources/topology_schemas/topology.sch.yaml
+ tags: [hw, 2-node]
+
+nodes:
+ TG:
+ type: TG
+ subtype: TREX
+ host: "${tg_public_ip}"
+ arch: x86_64
+ port: 22
+ username: testuser
+ password: Csit1234
+ interfaces:
+ port1:
+ # tg_instance/p1 - 100GE port1 on E810 NIC.
+ mac_address: "${tg_if1_mac}"
+ pci_address: "0000:00:05.0"
+ ip4_address: "172.16.10.2"
+ driver: iavf
+ link: link1
+ model: Intel-E810
+ port2:
+ # tg_instance/p2 - 100GE port2 on E810 NIC.
+ mac_address: "${tg_if2_mac}"
+ pci_address: "0000:00:06.0"
+ ip4_address: "172.16.20.2"
+ driver: iavf
+ link: link2
+ model: Intel-E810
+ DUT1:
+ type: DUT
+ host: "${dut1_public_ip}"
+ arch: x86_64
+ port: 22
+ username: testuser
+ password: Csit1234
+ uio_driver: vfio-pci
+ interfaces:
+ port1:
+ # dut1_instance/p1 - 100GE port1 on E810 NIC.
+ mac_address: "${dut1_if1_mac}"
+ pci_address: "0000:00:05.0"
+ ip4_address: "172.16.10.1"
+ driver: iavf
+ link: link1
+ model: Intel-E810
+ port2:
+ # dut1_instance/p2 - 100GE port2 on E810 NIC.
+ mac_address: "${dut1_if2_mac}"
+ pci_address: "0000:00:06.0"
+ ip4_address: "172.16.20.1"
+ driver: iavf
+ link: link2
+ model: Intel-E810 \ No newline at end of file
diff --git a/fdio.infra.terraform/terraform-openstack-2n/user-data-sut1 b/fdio.infra.terraform/terraform-openstack-2n/user-data-sut1
new file mode 100644
index 0000000000..9838f1b165
--- /dev/null
+++ b/fdio.infra.terraform/terraform-openstack-2n/user-data-sut1
@@ -0,0 +1,66 @@
+#cloud-config
+apt:
+ sources:
+ docker.list:
+ source: "deb [arch=amd64] https://download.docker.com/linux/ubuntu $RELEASE stable"
+ keyid: "9DC858229FC7DD38854AE2D88D81803C0EBFCD88"
+groups:
+ - "docker"
+hostname: "s02-t21-sut1"
+package_update: true
+packages:
+ - "apt-transport-https"
+ - "autoconf"
+ - "build-essential"
+ - "ca-certificates"
+ - "cgroup-tools"
+ - "curl"
+ - "dkms"
+ - "docker-ce"
+ - "docker-ce-cli"
+ - "gdb"
+ - "gnupg-agent"
+ - "iperf3"
+ - "libglib2.0-dev"
+ - "libmbedcrypto7"
+ - "libmbedtls14"
+ - "libmbedx509-1"
+ - "libnuma-dev"
+ - "libpixman-1-dev"
+ - "libpcap-dev"
+ - "libtool"
+ - "linux-tools-common"
+ - "lxc"
+ - "net-tools"
+ - "ninja-build"
+ - "numactl"
+ - "pkg-config"
+ - "python3-all"
+ - "python3-apt"
+ - "python3-cffi"
+ - "python3-cffi-backend"
+ - "python3-dev"
+ - "python3-pip"
+ - "python3-pyelftools"
+ - "python3-setuptools"
+ - "qemu-system"
+ - "screen"
+ - "socat"
+ - "software-properties-common"
+ - "unzip"
+ - "virtualenv"
+runcmd:
+ - sed -i '/PermitRootLogin/d' /etc/ssh/sshd_config
+ - echo "PermitRootLogin no" >> /etc/ssh/sshd_config
+ - systemctl restart sshd
+ - systemctl start docker
+ - systemctl enable docker
+ssh_pwauth: True
+users:
+ - name: "testuser"
+ groups: users, admin, docker, sudo
+ shell: "/bin/bash"
+ sudo:
+ - ALL=(ALL) NOPASSWD:ALL
+ lock_passwd: false
+ passwd: "$6$Y62lhMGJD8YNzmJn$H4DSqjrwFp5WN3tOvIrF.g/G2duOV76zXHAmaA/RU8jfT8H8sDumLQe/Q.EmI5pjPv7dzgI8j9BQPWes7efBK0" \ No newline at end of file
diff --git a/fdio.infra.terraform/terraform-openstack-2n/user-data-tg1 b/fdio.infra.terraform/terraform-openstack-2n/user-data-tg1
new file mode 100644
index 0000000000..59f6a481db
--- /dev/null
+++ b/fdio.infra.terraform/terraform-openstack-2n/user-data-tg1
@@ -0,0 +1,71 @@
+#cloud-config
+apt:
+ sources:
+ docker.list:
+ source: "deb [arch=amd64] https://download.docker.com/linux/ubuntu $RELEASE stable"
+ keyid: "9DC858229FC7DD38854AE2D88D81803C0EBFCD88"
+groups:
+ - "docker"
+hostname: "s01-t21-tg"
+package_update: true
+packages:
+ - "apt-transport-https"
+ - "autoconf"
+ - "build-essential"
+ - "ca-certificates"
+ - "cgroup-tools"
+ - "curl"
+ - "dkms"
+ - "docker-ce"
+ - "docker-ce-cli"
+ - "gcc-9"
+ - "g++-9"
+ - "gnupg-agent"
+ - "iperf3"
+ - "libmnl-dev"
+ - "libnuma-dev"
+ - "libpcap-dev"
+ - "librdmacm-dev"
+ - "librdmacm1"
+ - "libssl-dev"
+ - "linux-tools-common"
+ - "net-tools"
+ - "ninja-build"
+ - "numactl"
+ - "pciutils"
+ - "python3-all"
+ - "python3-apt"
+ - "python3-cffi"
+ - "python3-cffi-backend"
+ - "python3-dev"
+ - "python3-pip"
+ - "python3-pyelftools"
+ - "python3-setuptools"
+ - "qemu-system"
+ - "socat"
+ - "software-properties-common"
+ - "unzip"
+ - "virtualenv"
+ - "zlib1g-dev"
+runcmd:
+ - sed -i '/PermitRootLogin/d' /etc/ssh/sshd_config
+ - echo "PermitRootLogin no" >> /etc/ssh/sshd_config
+ - systemctl restart sshd
+ - systemctl start docker
+ - systemctl enable docker
+ - curl --proxy "http://[2620:0:cc8:11::1]:8888" -L http://github.com/cisco-system-traffic-generator/trex-core/archive/v3.03.tar.gz -o /opt/trex-core-v3.03.tar.gz
+ - mkdir -p /opt/trex-core-v3.03
+ - tar xzf /opt/trex-core-v3.03.tar.gz -C /opt/trex-core-v3.03 --strip-components=1
+ - cd /opt/trex-core-v3.03/linux_dpdk && ./b configure
+ - cd /opt/trex-core-v3.03/linux_dpdk && ./b build
+ - cd /opt/trex-core-v3.03/scripts/ko/src && make
+ - cd /opt/trex-core-v3.03/scripts/ko/src && make install
+ssh_pwauth: True
+users:
+ - name: "testuser"
+ groups: users, admin, docker, sudo
+ shell: "/bin/bash"
+ sudo:
+ - ALL=(ALL) NOPASSWD:ALL
+ lock_passwd: false
+ passwd: "$6$Y62lhMGJD8YNzmJn$H4DSqjrwFp5WN3tOvIrF.g/G2duOV76zXHAmaA/RU8jfT8H8sDumLQe/Q.EmI5pjPv7dzgI8j9BQPWes7efBK0"
diff --git a/fdio.infra.terraform/terraform-openstack-2n/variables.tf b/fdio.infra.terraform/terraform-openstack-2n/variables.tf
new file mode 100644
index 0000000000..d761016699
--- /dev/null
+++ b/fdio.infra.terraform/terraform-openstack-2n/variables.tf
@@ -0,0 +1,14 @@
+variable "flavour_name" {
+ description = "(Optional; Required if flavor_id is empty) The name of the desired flavor for the server. Changing this resizes the existing server."
+ type = string
+}
+
+variable "network_id_data" {
+ description = "(Required) The ID of the network to attach the port to. Changing this creates a new port."
+ type = string
+}
+
+variable "network_id_mgmt" {
+ description = "(Required) The ID of the network to attach the port to. Changing this creates a new port."
+ type = string
+}
diff --git a/fdio.infra.terraform/terraform-openstack-2n/versions.tf b/fdio.infra.terraform/terraform-openstack-2n/versions.tf
new file mode 100644
index 0000000000..1ad4a215b5
--- /dev/null
+++ b/fdio.infra.terraform/terraform-openstack-2n/versions.tf
@@ -0,0 +1,9 @@
+terraform {
+ required_providers {
+ openstack = {
+ source = "terraform-provider-openstack/openstack"
+ version = "~> 1.53.0"
+ }
+ }
+ required_version = ">= 1.4.2"
+} \ No newline at end of file