From 67367fe9a6ec404b44f53238742021823faa8b68 Mon Sep 17 00:00:00 2001 From: eili1s <183522504+eili1s@users.noreply.github.com> Date: Sun, 1 Nov 2026 01:25:21 +0100 Subject: [PATCH 1/3] feat(test): add network infrastructure stack --- environments/test/network/.terraform.lock.hcl | 38 ++++++++++++ environments/test/network/main.tf | 17 ++++++ environments/test/network/outputs.tf | 24 ++++++++ environments/test/network/providers.tf | 17 ++++++ .../test/network/terraform.tfvars.example | 18 ++++++ environments/test/network/variables.tf | 60 +++++++++++++++++++ 6 files changed, 174 insertions(+) create mode 100644 environments/test/network/.terraform.lock.hcl create mode 100644 environments/test/network/main.tf create mode 100644 environments/test/network/outputs.tf create mode 100644 environments/test/network/providers.tf create mode 100644 environments/test/network/terraform.tfvars.example create mode 100644 environments/test/network/variables.tf diff --git a/environments/test/network/.terraform.lock.hcl b/environments/test/network/.terraform.lock.hcl new file mode 100644 index 0000000..5de7e39 --- /dev/null +++ b/environments/test/network/.terraform.lock.hcl @@ -0,0 +1,38 @@ +# This file is maintained automatically by "tofu init". +# Manual edits may be lost in future updates. + +provider "registry.opentofu.org/terraform-provider-openstack/openstack" { + version = "3.4.0" + constraints = "~> 3.0" + hashes = [ + "h1:BB0YFgWM3KZTFY16pCYIzBqM4IpmDpT03m29VZEV2OU=", + "h1:CalEmc/Tn9xv1Xx2bX92EUdsF8z6Lldmb4/gwT5lSRw=", + "h1:DwSYyG1VNcEMUVY1GE9gbo2C3UPS8W2bFGk4WGVJnDY=", + "h1:FpAT7j83xnW4SkiUL6A0eXo9V1bYbABt1Eh467INBgk=", + "h1:FqJxdGUazKAfnZa11qT7h5PstlSTeE4xTKPUiWEgPmg=", + "h1:GgJWG1fXiDuRBcdDuzOWRW0TMW1Lx5N8O6+80v17LZc=", + "h1:HsPiqtbovSqh8jHAuMDR3tNeRNCOBEeHCvRbkgAHiaY=", + "h1:IwC35geJo3X96yLwIqcjSzoLL1Nt+6qJA6BoBMlGgMw=", + "h1:MVSoVvhjbu7s1pfYfsiYED8A++XfAoyOlSX1x9PW68E=", + "h1:YMwKmPy+svf02jWyflqaPaQVX3eIXciwGeA8uwYgRBw=", + "h1:n1yIddr5lsLoYBhlfUmCwIYiCsynDkLvzAE98Tceo/A=", + "h1:nON9j1AYtfbOAmaml0lcPCfEQcb0OLB0K693HjdFggQ=", + "h1:rqRC/cidHw8t2vQb85cjMoWThGSCWnkEmTmmNSaGBVs=", + "h1:tzU+JfFe/RN+7swp0k5V5wUmuZtRNOjKX+spIGcRuKM=", + "zh:11b3c88e24197a29b13cf5ab41771944bd16707b561645323e8cbb4f1da00b7b", + "zh:1c3e89cf19118fc07d7b04257251fc9897e722c16e0a0df7b07fcd261f8c12e7", + "zh:2dc60dbbbb822fbb1e7b17e3b89e3e6a7a8fe54a716d4477d2fa40f836c4de0f", + "zh:68f851e333f0ab2367e9b2680739d47e4151ca9f803934ef265f6fa70a28e6e0", + "zh:6995b0bcae5a291d7b0a4d3a5df109eb97f8d1d34be6eb27768fe29b5e0d8def", + "zh:7b68bf81891a0445c543629d4d160226a6f2d5e8e5ee4baf21e0221412437d17", + "zh:8f117b8b17280598a92c6202b183a77168fe573397cfb597b9c2028da281846d", + "zh:b0a23b990eb9260e9616fd8471f11b37485f92df0e5eef46cd286f87396b0e0a", + "zh:baa5052ab3207f3a996c1fd715935d79a4e1c57d3d24e3c549b6c20ea9307e38", + "zh:c012cbda058aa7b76b718074fd73829ecd4009ad98e3dafe496e5f26099625c0", + "zh:c1c95e5dbe546a935a62c63814aef04718b58dd4258e5da40d681b43322924e9", + "zh:c720bdbdf432041f99572bac40d24659239b989cbf1540f92ebb441900ac8bae", + "zh:c92ac802a3dd1abbf9c9ccf0aba1f261fe9f8c2e7fafc196c7119b73c25a0772", + "zh:fd4faf25ee72acef4ab12c93ea9c7a5ccb41315e8851609e08b37d3c91ea6584", + "zh:ff347392412fc7950635e2c1c5bb878d88b661c1c5ba052edd290d971a14028f", + ] +} diff --git a/environments/test/network/main.tf b/environments/test/network/main.tf new file mode 100644 index 0000000..2f85eef --- /dev/null +++ b/environments/test/network/main.tf @@ -0,0 +1,17 @@ +module "network" { + source = "../../../modules/network" + + network_name = var.network_name + + frontend_subnet_name = var.frontend_subnet_name + frontend_subnet_cidr = var.frontend_subnet_cidr + + backend_subnet_name = var.backend_subnet_name + backend_subnet_cidr = var.backend_subnet_cidr + + database_subnet_name = var.database_subnet_name + database_subnet_cidr = var.database_subnet_cidr + + router_name = var.router_name + external_network_name = var.external_network_name +} \ No newline at end of file diff --git a/environments/test/network/outputs.tf b/environments/test/network/outputs.tf new file mode 100644 index 0000000..efd2810 --- /dev/null +++ b/environments/test/network/outputs.tf @@ -0,0 +1,24 @@ +output "network_id" { + description = "ID of the TEST network" + value = module.network.network_id +} + +output "frontend_subnet_id" { + description = "ID of the TEST frontend subnet" + value = module.network.frontend_subnet_id +} + +output "backend_subnet_id" { + description = "ID of the TEST backend subnet" + value = module.network.backend_subnet_id +} + +output "database_subnet_id" { + description = "ID of the TEST database subnet" + value = module.network.database_subnet_id +} + +output "router_id" { + description = "ID of the TEST router" + value = module.network.router_id +} \ No newline at end of file diff --git a/environments/test/network/providers.tf b/environments/test/network/providers.tf new file mode 100644 index 0000000..206c7f4 --- /dev/null +++ b/environments/test/network/providers.tf @@ -0,0 +1,17 @@ +terraform { + required_version = ">= 1.12.0" + + required_providers { + openstack = { + source = "terraform-provider-openstack/openstack" + version = "~> 3" + } + } + + backend "kubernetes" { + namespace = "iac" + secret_suffix = "assignment2-test-network" + } +} + +provider "openstack" {} \ No newline at end of file diff --git a/environments/test/network/terraform.tfvars.example b/environments/test/network/terraform.tfvars.example new file mode 100644 index 0000000..638bf20 --- /dev/null +++ b/environments/test/network/terraform.tfvars.example @@ -0,0 +1,18 @@ +# Network +network_name = "assignment2-test-network" + +# Frontend subnet +frontend_subnet_name = "assignment2-test-frontend-subnet" +frontend_subnet_cidr = "10.60.10.0/24" + +# Backend subnet +backend_subnet_name = "assignment2-test-backend-subnet" +backend_subnet_cidr = "10.60.20.0/24" + +# Database subnet +database_subnet_name = "assignment2-test-database-subnet" +database_subnet_cidr = "10.60.30.0/24" + +# Router +router_name = "assignment2-test-router" +external_network_name = "ntnu-internal" \ No newline at end of file diff --git a/environments/test/network/variables.tf b/environments/test/network/variables.tf new file mode 100644 index 0000000..ce21774 --- /dev/null +++ b/environments/test/network/variables.tf @@ -0,0 +1,60 @@ +variable "network_name" { + description = "Name of the network" + type = string +} + +variable "frontend_subnet_name" { + description = "Name of the frontend subnet" + type = string +} + +variable "frontend_subnet_cidr" { + description = "CIDR block for the frontend subnet" + type = string + + validation { + condition = can(cidrhost(var.frontend_subnet_cidr, 0)) + error_message = "frontend_subnet_cidr must be a valid CIDR block." + } +} + +variable "backend_subnet_name" { + description = "Name of the backend subnet" + type = string +} + +variable "backend_subnet_cidr" { + description = "CIDR block for the backend subnet" + type = string + + validation { + condition = can(cidrhost(var.backend_subnet_cidr, 0)) + error_message = "backend_subnet_cidr must be a valid CIDR block." + } +} + +variable "database_subnet_name" { + description = "Name of the database subnet" + type = string +} + +variable "database_subnet_cidr" { + description = "CIDR block for the database subnet" + type = string + + validation { + condition = can(cidrhost(var.database_subnet_cidr, 0)) + error_message = "database_subnet_cidr must be a valid CIDR block." + } +} + +variable "router_name" { + description = "Name of the router" + type = string +} + +variable "external_network_name" { + description = "Name of the external network" + type = string + default = "ntnu-internal" +} \ No newline at end of file From 3518b698cac776e5f77a29c9f4f40723f5e2133e Mon Sep 17 00:00:00 2001 From: eili1s <183522504+eili1s@users.noreply.github.com> Date: Sun, 1 Nov 2026 02:03:49 +0100 Subject: [PATCH 2/3] feat(test): add frontend infrastructure stack --- .../test/frontend/.terraform.lock.hcl | 75 +++++++++++++++++++ .../test/frontend/cloud_init/nginx.yaml | 8 ++ environments/test/frontend/data.tf | 8 ++ environments/test/frontend/main.tf | 31 ++++++++ environments/test/frontend/outputs.tf | 24 ++++++ environments/test/frontend/providers.tf | 20 +++++ .../test/frontend/terraform.tfvars.example | 17 +++++ environments/test/frontend/variables.tf | 58 ++++++++++++++ 8 files changed, 241 insertions(+) create mode 100644 environments/test/frontend/.terraform.lock.hcl create mode 100644 environments/test/frontend/cloud_init/nginx.yaml create mode 100644 environments/test/frontend/data.tf create mode 100644 environments/test/frontend/main.tf create mode 100644 environments/test/frontend/outputs.tf create mode 100644 environments/test/frontend/providers.tf create mode 100644 environments/test/frontend/terraform.tfvars.example create mode 100644 environments/test/frontend/variables.tf diff --git a/environments/test/frontend/.terraform.lock.hcl b/environments/test/frontend/.terraform.lock.hcl new file mode 100644 index 0000000..e5c5f89 --- /dev/null +++ b/environments/test/frontend/.terraform.lock.hcl @@ -0,0 +1,75 @@ +# This file is maintained automatically by "tofu init". +# Manual edits may be lost in future updates. + +provider "registry.opentofu.org/hashicorp/cloudinit" { + version = "2.4.1" + constraints = "~> 2.0" + hashes = [ + "h1:+W0yP9aNwhxG6GkkvAvXAzR3c6oHFrsn0qKzCcd+Pt4=", + "h1:5//sVDkThzeCAUR3avaWF5QkFGoGNHQVohk/03XlwDY=", + "h1:ALxQFbm3LDD9sM9hnJpml3vjEgwwHlfWkynA3QULKzs=", + "h1:IglLKQ1PLLykMGHI5kJgs1KRkQGBHFbQGgwB8d2Evmc=", + "h1:Jp8AyBJHKvSuYUmzImcUJIPasR/dWpPFKHbYYrBkZIk=", + "h1:Q1wbRg2gy6rfc+02mx3am1X4XiQ3t3ohWrD0HhGps3U=", + "h1:QCJhqLabUHdUfcFCxT5RyKrIVyMH20vhvmcwlA3LKnM=", + "h1:SaRx0UjptcMTQe7RAscgvL4yWlniE9fozAY1n8rkWl0=", + "h1:U/s/xR8Qye5WW1Cktz8+J++rHRJCXy29EFXPLSGnxSQ=", + "h1:a3EYZ6Sk+eVf/AuEm8P/vXzHPLr8TfZoVJl2QLaULBQ=", + "h1:m+a2xKJJoawR7H3FF+gFOlBMt80VGnUIDBBCU5Fcp/E=", + "h1:tdO7350ZjYClrjddqhEzXEsX3duMOeKbxWGpRroqDNk=", + "h1:vBTV7h6otZu+5CUa5Mom6qRbGBol1KTgUSW48Z8LnY4=", + "h1:yELihyb80B8udu3NsTq9OYOirr+8+eToSe1ubKecDf8=", + "h1:zKTS0SR/2LWKBAIcUl/yTZulOzKsaYf7qajYARh+yns=", + "zh:1d4e8e1a6c9e87d2f481950d44d907353d8407c74fad3effd1e340a96b2a8ebf", + "zh:1e6070731a6b27d336d67a0a89f954e91efa410d6e309f871e1eb119068852ed", + "zh:2dc72816f28d66de9c7d36f9245dae11810c94321ec9ab54958e94cb077b3129", + "zh:375b260afb24a068e8ea3f9711c995d61eb90eafd8c2f1622a2792c098c67c0c", + "zh:3d7aa8f836560393e3e45243fbcf0a6eb1de429794897439cc9e174c89d2c515", + "zh:3eabd95f6cec88e4190dc1b4c5c1b437343da85633b5803722a08d870d2a203f", + "zh:44672aa5eb610f846af5dfa705b6a8339aea82648b64a4247c0e55a8be590695", + "zh:491020b29c7efdb2288b61babdbd8467315cf3b4e9cf903335cf6f6095d80898", + "zh:520cd99f2c25d0aa22846e650c96f7800837a7e4e666a47e1e42c8e99d3423bd", + "zh:8342d7961404864b0fa4bb36dc686b5e04cbf8771e407cba961c44b8ca3158f0", + "zh:9330950100da6c4a04a6d4806407ab9ab686e079bd7475cff08f7f646cfbd440", + "zh:e12f3bfbee3534b9b0f3310fa80697ef0cca0ff473b6a5c99e457758a366c786", + "zh:eebe47e46ccbff9acf987c653032460e4e572248b1aa7eafce8e340f2120217a", + "zh:ef75fe7352b12b5e5fc968cb9993a94f81101b12766ada290cf1509fb202823f", + "zh:f3b5a1d9fae6e42d8a40cdbb31d6dbbf59a837a7e351b049dfe38474fc26a0ac", + ] +} + +provider "registry.opentofu.org/terraform-provider-openstack/openstack" { + version = "3.4.0" + constraints = "~> 3.0" + hashes = [ + "h1:BB0YFgWM3KZTFY16pCYIzBqM4IpmDpT03m29VZEV2OU=", + "h1:CalEmc/Tn9xv1Xx2bX92EUdsF8z6Lldmb4/gwT5lSRw=", + "h1:DwSYyG1VNcEMUVY1GE9gbo2C3UPS8W2bFGk4WGVJnDY=", + "h1:FpAT7j83xnW4SkiUL6A0eXo9V1bYbABt1Eh467INBgk=", + "h1:FqJxdGUazKAfnZa11qT7h5PstlSTeE4xTKPUiWEgPmg=", + "h1:GgJWG1fXiDuRBcdDuzOWRW0TMW1Lx5N8O6+80v17LZc=", + "h1:HsPiqtbovSqh8jHAuMDR3tNeRNCOBEeHCvRbkgAHiaY=", + "h1:IwC35geJo3X96yLwIqcjSzoLL1Nt+6qJA6BoBMlGgMw=", + "h1:MVSoVvhjbu7s1pfYfsiYED8A++XfAoyOlSX1x9PW68E=", + "h1:YMwKmPy+svf02jWyflqaPaQVX3eIXciwGeA8uwYgRBw=", + "h1:n1yIddr5lsLoYBhlfUmCwIYiCsynDkLvzAE98Tceo/A=", + "h1:nON9j1AYtfbOAmaml0lcPCfEQcb0OLB0K693HjdFggQ=", + "h1:rqRC/cidHw8t2vQb85cjMoWThGSCWnkEmTmmNSaGBVs=", + "h1:tzU+JfFe/RN+7swp0k5V5wUmuZtRNOjKX+spIGcRuKM=", + "zh:11b3c88e24197a29b13cf5ab41771944bd16707b561645323e8cbb4f1da00b7b", + "zh:1c3e89cf19118fc07d7b04257251fc9897e722c16e0a0df7b07fcd261f8c12e7", + "zh:2dc60dbbbb822fbb1e7b17e3b89e3e6a7a8fe54a716d4477d2fa40f836c4de0f", + "zh:68f851e333f0ab2367e9b2680739d47e4151ca9f803934ef265f6fa70a28e6e0", + "zh:6995b0bcae5a291d7b0a4d3a5df109eb97f8d1d34be6eb27768fe29b5e0d8def", + "zh:7b68bf81891a0445c543629d4d160226a6f2d5e8e5ee4baf21e0221412437d17", + "zh:8f117b8b17280598a92c6202b183a77168fe573397cfb597b9c2028da281846d", + "zh:b0a23b990eb9260e9616fd8471f11b37485f92df0e5eef46cd286f87396b0e0a", + "zh:baa5052ab3207f3a996c1fd715935d79a4e1c57d3d24e3c549b6c20ea9307e38", + "zh:c012cbda058aa7b76b718074fd73829ecd4009ad98e3dafe496e5f26099625c0", + "zh:c1c95e5dbe546a935a62c63814aef04718b58dd4258e5da40d681b43322924e9", + "zh:c720bdbdf432041f99572bac40d24659239b989cbf1540f92ebb441900ac8bae", + "zh:c92ac802a3dd1abbf9c9ccf0aba1f261fe9f8c2e7fafc196c7119b73c25a0772", + "zh:fd4faf25ee72acef4ab12c93ea9c7a5ccb41315e8851609e08b37d3c91ea6584", + "zh:ff347392412fc7950635e2c1c5bb878d88b661c1c5ba052edd290d971a14028f", + ] +} diff --git a/environments/test/frontend/cloud_init/nginx.yaml b/environments/test/frontend/cloud_init/nginx.yaml new file mode 100644 index 0000000..0d5e3f6 --- /dev/null +++ b/environments/test/frontend/cloud_init/nginx.yaml @@ -0,0 +1,8 @@ +#cloud-config +package_update: true + +packages: + - nginx + +runcmd: + - systemctl enable --now nginx \ No newline at end of file diff --git a/environments/test/frontend/data.tf b/environments/test/frontend/data.tf new file mode 100644 index 0000000..84c2b9f --- /dev/null +++ b/environments/test/frontend/data.tf @@ -0,0 +1,8 @@ +data "terraform_remote_state" "network" { + backend = "kubernetes" + + config = { + namespace = "iac" + secret_suffix = "assignment2-test-network" + } +} \ No newline at end of file diff --git a/environments/test/frontend/main.tf b/environments/test/frontend/main.tf new file mode 100644 index 0000000..af3ffa1 --- /dev/null +++ b/environments/test/frontend/main.tf @@ -0,0 +1,31 @@ + +module "frontend_vm" { + source = "../../../modules/vm" + count = var.frontend_count + + name = format("%s-%02d", var.frontend_name, count.index + 1) + distro = var.frontend_image + flavor = var.frontend_flavor + ssh_key_name = var.ssh_key_name + + network_id = data.terraform_remote_state.network.outputs.network_id + subnet_id = data.terraform_remote_state.network.outputs.frontend_subnet_id + + template = "${path.module}/cloud_init/nginx.yaml" + + enable_fip = true + ntnu_internal_network = var.external_network_name + + security_group_rules = [ + { + port = 22 + protocol = "tcp" + remote_ip_prefix = var.admin_cidr + }, + { + port = 80 + protocol = "tcp" + remote_ip_prefix = var.http_cidr + } + ] +} \ No newline at end of file diff --git a/environments/test/frontend/outputs.tf b/environments/test/frontend/outputs.tf new file mode 100644 index 0000000..49a1e2b --- /dev/null +++ b/environments/test/frontend/outputs.tf @@ -0,0 +1,24 @@ +output "frontend_vm_ids" { + description = "IDs of the TEST frontend VMs" + value = module.frontend_vm[*].vm_id +} + +output "frontend_vm_names" { + description = "Names of the TEST frontend VMs" + value = module.frontend_vm[*].vm_name +} + +output "frontend_private_ips" { + description = "Private IP addresses of the TEST frontend VMs" + value = module.frontend_vm[*].private_ip +} + +output "frontend_floating_ips" { + description = "Floating IP addresses of the TEST frontend VMs" + value = module.frontend_vm[*].floating_ip +} + +output "frontend_security_group_ids" { + description = "Security group IDs of the TEST frontend VMs" + value = module.frontend_vm[*].security_group_id +} \ No newline at end of file diff --git a/environments/test/frontend/providers.tf b/environments/test/frontend/providers.tf new file mode 100644 index 0000000..f3e74cb --- /dev/null +++ b/environments/test/frontend/providers.tf @@ -0,0 +1,20 @@ +terraform { + required_version = ">= 1.12.0" + + required_providers { + openstack = { + source = "terraform-provider-openstack/openstack" + version = "~> 3" + } + + cloudinit = { + source = "hashicorp/cloudinit" + version = "~> 2" + } + } + + backend "kubernetes" { + namespace = "iac" + secret_suffix = "assignment2-test-frontend" + } +} \ No newline at end of file diff --git a/environments/test/frontend/terraform.tfvars.example b/environments/test/frontend/terraform.tfvars.example new file mode 100644 index 0000000..df00f79 --- /dev/null +++ b/environments/test/frontend/terraform.tfvars.example @@ -0,0 +1,17 @@ +# Frontend VM +frontend_name = "assignment2-test-frontend" +frontend_count = 1 + +# Image and flavor +frontend_image = "Debian 13 (Trixie) stable amd64" +frontend_flavor = "gx1.1c1r" + +# SSH +ssh_key_name = "YOUR_SSH_KEYPAIR_NAME" + +# Security group rules +admin_cidr = "YOUR_ADMIN_CIDR" +http_cidr = "YOUR_HTTP_CIDR" + +# External network +external_network_name = "ntnu-internal" \ No newline at end of file diff --git a/environments/test/frontend/variables.tf b/environments/test/frontend/variables.tf new file mode 100644 index 0000000..ab87701 --- /dev/null +++ b/environments/test/frontend/variables.tf @@ -0,0 +1,58 @@ +variable "frontend_name" { + description = "Name of the frontend VM" + type = string +} + +variable "frontend_image" { + description = "OpenStack image used for the frontend VM" + type = string + default = "Debian 13 (Trixie) stable amd64" +} + +variable "frontend_flavor" { + description = "OpenStack flavor used for the frontend VM" + type = string + default = "gx1.1c1r" +} + +variable "ssh_key_name" { + description = "SSH keypair available in SkyHiGh" + type = string +} + +variable "admin_cidr" { + description = "CIDR range allowed to access the frontend VM via SSH" + type = string + + validation { + condition = can(cidrhost(var.admin_cidr, 0)) + error_message = "admin_cidr must be a valid CIDR block." + } +} + +variable "http_cidr" { + description = "CIDR range allowed to access the frontend VM via HTTP" + type = string + + validation { + condition = can(cidrhost(var.http_cidr, 0)) + error_message = "http_cidr must be a valid CIDR block." + } +} + +variable "external_network_name" { + description = "Name of the external network used for floating IP allocation" + type = string + default = "ntnu-internal" +} + +variable "frontend_count" { + description = "Number of frontend VMs to create" + type = number + default = 1 + + validation { + condition = var.frontend_count >= 1 && floor(var.frontend_count) == var.frontend_count + error_message = "frontend_count must be a positive integer." + } +} \ No newline at end of file From 9aa11e71a16bc6f11b2d57354bafe148416a01d3 Mon Sep 17 00:00:00 2001 From: eili1s <183522504+eili1s@users.noreply.github.com> Date: Sun, 1 Nov 2026 02:19:20 +0100 Subject: [PATCH 3/3] ci: extend validation to TEST network and frontend stacks --- .github/workflows/ci.yml | 53 ++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ad57ba3..cba0387 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,43 +1,70 @@ name: CI +# Run validation whenever changes are proposed or merged into main. +# Manual execution is also supported through GitHub Actions. on: - pull_request: - branches: [main] push: branches: [main] + pull_request: + branches: [main] workflow_dispatch: +# Prevent redundant CI runs for the same branch or pull request. +# Only superseded pull request runs are cancelled, ensuring that +# every commit pushed to main can complete its validation. +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + # Only cancel superseded pull request runs. + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +# CI only needs to read repository contents. +# Infrastructure deployment permissions are handled separately. permissions: contents: read jobs: - validate: - name: Validate OpenTofu + check: + name: Format and validate infrastructure runs-on: [self-hosted, linux, assignment2] - timeout-minutes: 15 + timeout-minutes: 30 steps: - - name: Checkout repository + # Retrieve the repository without persisting Git credentials. + - name: Checkout uses: actions/checkout@v5 with: persist-credentials: false + # Install a consistent OpenTofu version across CI runs. - name: Setup OpenTofu uses: opentofu/setup-opentofu@v2 with: tofu_version: "1.12.6" tofu_wrapper: false + # Enforce consistent formatting across all OpenTofu configurations - name: Check formatting run: tofu fmt -check -recursive - - name: Initialize bootstrap configuration + # Initialize providers and modules without connecting to remote state. + # The committed lock file ensures consistent provider versions. + # Validation checks configuration correctness without deploying resources. + - name: Validate bootstrap working-directory: bootstrap - # Skip backend initialization - run: tofu init -backend=false -input=false + run: | + tofu init -backend=false -input=false -lockfile=readonly + tofu validate -no-color - - name: Validate bootstrap configuration - working-directory: bootstrap - # Validate without accessing Openstack resources - run: tofu validate -no-color + # Validate the TEST network stack independently of other stacks. + - name: Validate TEST network + working-directory: environments/test/network + run: | + tofu init -backend=false -input=false -lockfile=readonly + tofu validate -no-color + # Validate the TEST frontend stack without requiring deployed infrastructure. + - name: Validate TEST frontend + working-directory: environments/test/frontend + run: | + tofu init -backend=false -input=false -lockfile=readonly + tofu validate -no-color \ No newline at end of file