Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,34 @@ jobs:
tofu init -backend=false -input=false -lockfile=readonly
tofu validate -no-color
# Validate the STAGE network stack.
- name: Validate STAGE network
working-directory: environments/stage/network
run: |
tofu init -backend=false -input=false -lockfile=readonly
tofu validate -no-color
# Validate the STAGE frontend stack.
- name: Validate STAGE frontend
working-directory: environments/stage/frontend
run: |
tofu init -backend=false -input=false -lockfile=readonly
tofu validate -no-color
# Validate the PROD network stack.
- name: Validate PROD network
working-directory: environments/prod/network
run: |
tofu init -backend=false -input=false -lockfile=readonly
tofu validate -no-color
# Validate the PROD frontend stack.
- name: Validate PROD frontend
working-directory: environments/prod/frontend
run: |
tofu init -backend=false -input=false -lockfile=readonly
tofu validate -no-color
# Install a pinned TFLint version for static code analysis.
- name: Setup TFLint
uses: terraform-linters/setup-tflint@v6
Expand Down
75 changes: 75 additions & 0 deletions environments/prod/frontend/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions environments/prod/frontend/cloud_init/nginx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#cloud-config
package_update: true

packages:
- nginx

runcmd:
- systemctl enable --now nginx
8 changes: 8 additions & 0 deletions environments/prod/frontend/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
data "terraform_remote_state" "network" {
backend = "kubernetes"

config = {
namespace = "iac"
secret_suffix = "assignment2-prod-network"
}
}
31 changes: 31 additions & 0 deletions environments/prod/frontend/main.tf
Original file line number Diff line number Diff line change
@@ -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
}
]
}
24 changes: 24 additions & 0 deletions environments/prod/frontend/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
output "frontend_vm_ids" {
description = "IDs of the PROD frontend VMs"
value = module.frontend_vm[*].vm_id
}

output "frontend_vm_names" {
description = "Names of the PROD frontend VMs"
value = module.frontend_vm[*].vm_name
}

output "frontend_private_ips" {
description = "Private IP addresses of the PROD frontend VMs"
value = module.frontend_vm[*].private_ip
}

output "frontend_floating_ips" {
description = "Floating IP addresses of the PROD frontend VMs"
value = module.frontend_vm[*].floating_ip
}

output "frontend_security_group_ids" {
description = "Security group IDs of the PROD frontend VMs"
value = module.frontend_vm[*].security_group_id
}
20 changes: 20 additions & 0 deletions environments/prod/frontend/providers.tf
Original file line number Diff line number Diff line change
@@ -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-prod-frontend"
}
}
17 changes: 17 additions & 0 deletions environments/prod/frontend/terraform.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Frontend VM
frontend_name = "assignment2-prod-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"
58 changes: 58 additions & 0 deletions environments/prod/frontend/variables.tf
Original file line number Diff line number Diff line change
@@ -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."
}
}
38 changes: 38 additions & 0 deletions environments/prod/network/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions environments/prod/network/main.tf
Original file line number Diff line number Diff line change
@@ -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
}
24 changes: 24 additions & 0 deletions environments/prod/network/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
output "network_id" {
description = "ID of the PROD network"
value = module.network.network_id
}

output "frontend_subnet_id" {
description = "ID of the PROD frontend subnet"
value = module.network.frontend_subnet_id
}

output "backend_subnet_id" {
description = "ID of the PROD backend subnet"
value = module.network.backend_subnet_id
}

output "database_subnet_id" {
description = "ID of the PROD database subnet"
value = module.network.database_subnet_id
}

output "router_id" {
description = "ID of the PROD router"
value = module.network.router_id
}
17 changes: 17 additions & 0 deletions environments/prod/network/providers.tf
Original file line number Diff line number Diff line change
@@ -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-prod-network"
}
}

provider "openstack" {}
Loading