revert to old structure

This commit is contained in:
Maximilian_Schlenz 2025-07-15 12:04:25 +02:00
parent a495f53751
commit bb841ad2a3
15 changed files with 321 additions and 243 deletions

View file

@ -1,66 +1,78 @@
module "project" {
source = "../project"
name = "project-1"
organization_id = var.organization_id
owner_email = "maximilian.schlenz@stackit.cloud"
}
module "security_groups" { module "security_groups" {
source = "../security-group" source = "../security-group"
for_each = var.security_groups for_each = var.security_groups
project_id = var.project_id project_id = module.project.project_id
name = each.value.name name = each.value.name
description = each.value.description description = each.value.description
rules = each.value.rules rules = each.value.rules
} }
module "postgres" { # module "postgres" {
source = "../postgres" # source = "../postgres"
for_each = var.postgres_instances # for_each = var.postgres_instances
project_id = var.project_id # project_id = module.project.project_id
name = each.value.name # name = each.value.name
ver = each.value.version # ver = each.value.version
flavor = each.value.flavor # flavor = each.value.flavor
storage = each.value.storage # storage = each.value.storage
replicas = each.value.replicas # replicas = each.value.replicas
acl = each.value.acl # acl = each.value.acl
backup_schedule = each.value.backup_schedule # backup_schedule = each.value.backup_schedule
users = each.value.users # users = each.value.users
databases = each.value.databases # databases = each.value.databases
} # }
module "net" { module "net" {
source = "../network" depends_on = [module.security_groups]
source = "../network"
for_each = var.networks for_each = var.networks
project_id = var.project_id project_id = module.project.project_id
name = each.value.name name = each.value.name
ipv4_nameservers = each.value.ipv4_nameservers ipv4_nameservers = each.value.ipv4_nameservers
labels = each.value.labels labels = each.value.labels
nic_ipv4 = each.value.nic_ipv4 nic_ipv4 = each.value.nic_ipv4
nic_name = each.value.nic_name nic_name = each.value.nic_name
nic_allowed_addresses = each.value.nic_allowed_addresses nic_allowed_addresses = each.value.nic_allowed_addresses
nic_labels = each.value.nic_labels nic_labels = each.value.nic_labels
nic_security = each.value.nic_security nic_security = each.value.nic_security
nic_security_group_ids = each.value.nic_security_group_ids
nic_security_group_ids = [
module.security_groups["ssh_ingress_group"].security_group_id,
]
} }
module "ske" { # module "ske" {
source = "../ske" # source = "../ske"
for_each = var.ske_clusters # for_each = var.ske_clusters
project_id = var.project_id # project_id = module.project.project_id
name = each.value.name # name = each.value.name
kubernetes_version_min = each.value.kubernetes_version_min # kubernetes_version_min = each.value.kubernetes_version_min
node_pools = each.value.node_pools # node_pools = each.value.node_pools
} # }
module "observability" { # module "observability" {
source = "../observability" # source = "../observability"
for_each = var.observability_instances # for_each = var.observability_instances
project_id = var.project_id # project_id = module.project.project_id
name = each.value.name # name = each.value.name
plan_name = each.value.plan_name # plan_name = each.value.plan_name
} # }

View file

@ -1,6 +1,7 @@
region = "eu01" region = "eu01"
service_account_token = "" service_account_token = ""
# project_id = "b25685da-5954-4382-b654-62abd9f0ef77" project_id = ""
organization_id = "03a34540-3c1a-4794-b2c6-7111ecf824ef"
service_account_key_path = "/Users/schlenz/sa-key-dd5fa2c9-1651-4da7-8404-9ac4fe9bc3d5.json" service_account_key_path = "/Users/schlenz/sa-key-dd5fa2c9-1651-4da7-8404-9ac4fe9bc3d5.json"
security_groups = { security_groups = {
@ -23,126 +24,129 @@ security_groups = {
] ]
}, },
web_traffic_group = { # web_traffic_group = {
name = "web-traffic-group" # name = "web-traffic-group"
description = "ALLOW WEB TRAFFIC ingress" # description = "ALLOW WEB TRAFFIC ingress"
rules = [ # rules = [
{ description = "ALLOW ALL 80" # { description = "ALLOW ALL 80"
direction = "ingress" # direction = "ingress"
ether_type = "IPv4" # ether_type = "IPv4"
ip_range = "0.0.0.0/0" # ip_range = "0.0.0.0/0"
protocol = { # protocol = {
name = "tcp" # name = "tcp"
} # }
port_range = { # port_range = {
min = 80 # min = 80
max = 80 # max = 80
} # }
}, # },
{ description = "ALLOW ALL 443" # { description = "ALLOW ALL 443"
direction = "ingress" # direction = "ingress"
ether_type = "IPv4" # ether_type = "IPv4"
ip_range = "0.0.0.0/0" # ip_range = "0.0.0.0/0"
protocol = { # protocol = {
name = "tcp" # name = "tcp"
} # }
port_range = { # port_range = {
min = 443 # min = 443
max = 443 # max = 443
} # }
}, # },
] # ]
}, # },
} }
postgres_instances = { # postgres_instances = {
dev = { # dev = {
name = "pg-test-instance" # name = "pg-test-instance"
version = 17 # version = 17
flavor = { # flavor = {
cpu = 2, # cpu = 2,
ram = 4 # ram = 4
} # }
storage = { # storage = {
class = "premium-perf6-stackit", # class = "premium-perf6-stackit",
size = 20 # size = 20
} # }
replicas = 1 # replicas = 1
acl = ["0.0.0.0/0"] # acl = ["0.0.0.0/0"]
backup_schedule = "00 00 * * *" # backup_schedule = "00 00 * * *"
users = [ # users = [
{ username = "admin", # { username = "admin",
roles = ["login", "createdb"] # roles = ["login", "createdb"]
}, # },
{ username = "testusr", # { username = "testusr",
roles = ["login"] # roles = ["login"]
} # }
] # ]
databases = [ # databases = [
{ # {
name = "test_db", # name = "test_db",
owner = "admin" # owner = "admin"
} # }
] # ]
} # }
} # }
networks = { networks = {
web = { # web = {
name = "web-net" # name = "web-net"
ipv4_nameservers = ["1.1.1.1", "8.8.8.8"] # ipv4_nameservers = ["1.1.1.1", "8.8.8.8"]
labels = { # labels = {
env = "prod" # env = "prod"
} # }
} # }
db = { db = {
name = "db-net" name = "db-net"
nic_ipv4 = "10.0.2.120" nic_ipv4 = "10.0.0.126"
nic_security = false nic_security = true
security_groups = {
}
} }
} }
ske_clusters = { # ske_clusters = {
dev = { # dev = {
name = "dev-cluster" # name = "dev-cluster"
kubernetes_version_min = "1.31" # kubernetes_version_min = "1.31"
node_pools = [ # node_pools = [
{ name = "default" # { name = "default"
machine_type = "c2.1" # machine_type = "c2.1"
availability_zones = ["eu01-1", "eu01-2"] # availability_zones = ["eu01-1", "eu01-2"]
volume_size = 40 # volume_size = 40
minimum = 1 # minimum = 1
maximum = 3 # maximum = 3
} # }
] # ]
} # }
staging = { # staging = {
name = "staging-cluster" # name = "staging-cluster"
kubernetes_version_min = "1.31" # kubernetes_version_min = "1.31"
node_pools = [ # node_pools = [
{ name = "general" # { name = "general"
machine_type = "c2.2" # machine_type = "c2.2"
availability_zones = ["eu03-1", "eu03-2"] # availability_zones = ["eu03-1", "eu03-2"]
volume_size = 80 # volume_size = 80
minimum = 2 # minimum = 2
maximum = 4 # maximum = 4
} # }
] # ]
} # }
} # }
observability_instances = { # observability_instances = {
starter = { # starter = {
name = "Observability-1" # name = "Observability-1"
plan_name = "Observability-Starter-EU01" # plan_name = "Observability-Starter-EU01"
} # }
prod = { # prod = {
name = "Observability-2" # name = "Observability-2"
plan_name = "Observability-Large-EU01" # plan_name = "Observability-Large-EU01"
} # }
} # }

View file

@ -20,6 +20,17 @@ variable "service_account_key_path" {
default = "" default = ""
} }
variable "organization_id" {
description = "Organization ID"
type = string
}
variable "owner_email" {
description = "Email of the project owner"
type = string
default = null
}
variable "security_groups" { variable "security_groups" {
type = map(object({ type = map(object({
name = optional(string) name = optional(string)
@ -46,25 +57,25 @@ variable "security_groups" {
})) }))
} }
variable "postgres_instances" { # variable "postgres_instances" {
type = map(object({ # type = map(object({
name = string # name = string
version = number # version = number
flavor = object({ cpu = number, ram = number }) # flavor = object({ cpu = number, ram = number })
storage = object({ class = string, size = number }) # storage = object({ class = string, size = number })
replicas = number # replicas = number
acl = list(string) # acl = list(string)
backup_schedule = string # backup_schedule = string
users = list(object({ # users = list(object({
username = string # username = string
roles = set(string) # roles = set(string)
})) # }))
databases = list(object({ # databases = list(object({
name = string # name = string
owner = string # owner = string
})) # }))
})) # }))
} # }
variable "networks" { variable "networks" {
type = map(object({ type = map(object({
@ -74,7 +85,7 @@ variable "networks" {
labels = optional(map(string)) labels = optional(map(string))
nic_ipv4 = optional(string) nic_ipv4 = optional(string)
nic_name = optional(string) nic_name = optional(string)
nic_allowed_addresses = optional(list(string)) nic_allowed_addresses = optional(list(string))
nic_labels = optional(map(string)) nic_labels = optional(map(string))
@ -83,24 +94,24 @@ variable "networks" {
})) }))
} }
variable "ske_clusters" { # variable "ske_clusters" {
type = map(object({ # type = map(object({
name = string # name = string
kubernetes_version_min = string # kubernetes_version_min = string
node_pools = list(object({ # node_pools = list(object({
name = string # name = string
machine_type = string # machine_type = string
availability_zones = list(string) # availability_zones = list(string)
volume_size = number # volume_size = number
minimum = number # minimum = number
maximum = number # maximum = number
})) # }))
})) # }))
} # }
variable "observability_instances" { # variable "observability_instances" {
type = map(object({ # type = map(object({
name = string # name = string
plan_name = string # plan_name = string
})) # }))
} # }

View file

@ -2,18 +2,18 @@ resource "stackit_network" "this" {
project_id = var.project_id project_id = var.project_id
name = var.name name = var.name
ipv4_gateway = var.routed == false ? var.ipv4_gateway : null ipv4_gateway = var.routed == false ? var.ipv4_gateway : null
ipv4_nameservers = var.ipv4_nameservers ipv4_nameservers = var.ipv4_nameservers
ipv4_prefix = var.ipv4_prefix ipv4_prefix = var.ipv4_prefix
ipv4_prefix_length = var.ipv4_prefix_length ipv4_prefix_length = var.ipv4_prefix_length
ipv6_gateway = var.routed == false ? var.ipv6_gateway : null ipv6_gateway = var.routed == false ? var.ipv6_gateway : null
ipv6_nameservers = var.ipv6_nameservers ipv6_nameservers = var.ipv6_nameservers
ipv6_prefix = var.ipv6_prefix ipv6_prefix = var.ipv6_prefix
ipv6_prefix_length = var.ipv6_prefix_length ipv6_prefix_length = var.ipv6_prefix_length
labels = var.labels labels = var.labels
no_ipv4_gateway = var.no_ipv4_gateway no_ipv4_gateway = var.no_ipv4_gateway
no_ipv6_gateway = var.no_ipv6_gateway no_ipv6_gateway = var.no_ipv6_gateway
routed = var.routed routed = var.routed
} }
resource "stackit_network_interface" "static" { resource "stackit_network_interface" "static" {

View file

@ -87,8 +87,8 @@ variable "nic_name" {
} }
variable "nic_security" { variable "nic_security" {
type = bool type = bool
default = false default = false
nullable = false nullable = false
} }
@ -96,3 +96,8 @@ variable "nic_security_group_ids" {
type = list(string) type = list(string)
default = [] default = []
} }
variable "nic_security_group_names" {
type = list(string)
default = []
}

View file

@ -1,34 +1,6 @@
variable "projects" { resource "stackit_resourcemanager_project" "this" {
type = map(object({ parent_container_id = var.organization_id
name = string name = var.name
owner_email = string labels = var.labels
})) owner_email = var.owner_email
default = {
project1 = {
name = "project-alpha"
owner_email = "michael.sodan@stackit.cloud"
}
project2 = {
name = "project-beta"
owner_email = "michael.sodan@stackit.cloud"
}
}
} }
resource "stackit_resourcemanager_project" "projects" {
for_each = var.projects
parent_container_id = var.organization_id # Nutzt jetzt die übergebene Variable
name = each.value.name
owner_email = each.value.owner_email
# labels = { ... } # Vorerst entfernt, da stackit_network_area nicht definiert war
}
output "project_info" {
value = {
for k, project in stackit_resourcemanager_project.projects : k => {
project_id = project.project_id
container_id = project.container_id
}
}
}

4
project/output.tf Normal file
View file

@ -0,0 +1,4 @@
output "project_id" {
value = stackit_resourcemanager_project.this.id
description = "ID of the project"
}

9
project/providers.tf Normal file
View file

@ -0,0 +1,9 @@
terraform {
required_version = ">= 1.9.0"
required_providers {
stackit = {
source = "stackitcloud/stackit"
version = "0.56.0"
}
}
}

View file

@ -1,10 +1,27 @@
variable "organization_id" { variable "organization_id" {
description = "Empfängt die Container-ID der Organisation vom Root-Modul." type = string
type = string
} }
variable "sna_net" { variable "name" {
description = "SNA Transfer Network" type = string
type = string
} }
variable "description" {
type = string
default = null
}
variable "labels" {
type = map(string)
default = {}
}
variable "project_id" {
type = string
default = null
}
variable "owner_email" {
type = string
default = null
}

34
project_old/main.tf Normal file
View file

@ -0,0 +1,34 @@
variable "projects" {
type = map(object({
name = string
owner_email = string
}))
default = {
project1 = {
name = "project-alpha"
owner_email = "michael.sodan@stackit.cloud"
}
project2 = {
name = "project-beta"
owner_email = "michael.sodan@stackit.cloud"
}
}
}
resource "stackit_resourcemanager_project" "projects" {
for_each = var.projects
parent_container_id = var.organization_id # Nutzt jetzt die übergebene Variable
name = each.value.name
owner_email = each.value.owner_email
# labels = { ... } # Vorerst entfernt, da stackit_network_area nicht definiert war
}
output "project_info" {
value = {
for k, project in stackit_resourcemanager_project.projects : k => {
project_id = project.project_id
container_id = project.container_id
}
}
}

10
project_old/variables.tf Normal file
View file

@ -0,0 +1,10 @@
variable "organization_id" {
description = "Empfängt die Container-ID der Organisation vom Root-Modul."
type = string
}
variable "sna_net" {
description = "SNA Transfer Network"
type = string
}

View file

@ -13,7 +13,7 @@ resource "stackit_security_group_rule" "rule" {
direction = var.rules[count.index].direction direction = var.rules[count.index].direction
project_id = var.project_id project_id = var.project_id
security_group_id = stackit_security_group.this.id security_group_id = stackit_security_group.this.security_group_id
description = var.rules[count.index].description description = var.rules[count.index].description
ether_type = var.rules[count.index].ether_type ether_type = var.rules[count.index].ether_type