add module for security-group and security-group-rule

This commit is contained in:
Maximilian_Schlenz 2025-07-04 14:57:27 +02:00
parent 4e9fc826bf
commit 3a41f0d302
8 changed files with 103 additions and 0 deletions

View file

@ -0,0 +1,19 @@
locals {
rule_count = length(var.rules)
}
resource "stackit_security_group_rule" "this" {
count = local.rule_count
project_id = var.project_id
security_group_id = var.security_group_id
direction = var.rules[count.index].direction
description = var.rules[count.index].description
ether_type = var.rules[count.index].ether_type
icmp_parameters = var.rules[count.index].icmp_parameters
ip_range = var.rules[count.index].ip_range
port_range = var.rules[count.index].port_range
protocol = var.rules[count.index].protocol
remote_security_group_id = var.rules[count.index].remote_security_group_id
}

View file

@ -0,0 +1,3 @@
output "rule_ids" {
value = stackit_security_group_rule.this[*].id
}

View file

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

View file

@ -0,0 +1,39 @@
variable "project_id" {
type = string
}
variable "security_group_id" {
type = string
}
variable "rules" {
type = list(object({
direction = string
description = optional(string)
ether_type = optional(string)
icmp_parameters = optional(object({
type = optional(number)
code = optional(number)
}))
ip_range = optional(string)
port_range = optional(object({
min = number
max = number
}))
protocol = optional(object({
name = optional(string)
number = optional(number)
}))
remote_security_group_id = optional(string)
}))
default = []
validation {
condition = alltrue([
for rule in var.rules : contains(["ingress", "egress"], rule.direction)
# ... need more validations
])
error_message = "Direction must be either \"ingress\" or \"egress\"."
}
}

5
security-group/main.tf Normal file
View file

@ -0,0 +1,5 @@
resource "stackit_security_group" "this" {
project_id = var.project_id
name = var.name
description = var.description == null ? var.name : var.description
}

7
security-group/output.tf Normal file
View file

@ -0,0 +1,7 @@
output "id" {
value = stackit_security_group.this.security_group_id
}
output "name" {
value = stackit_security_group.this.name
}

View file

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

View file

@ -0,0 +1,12 @@
variable "project_id" {
type = string
}
variable "name" {
type = string
}
variable "description" {
type = string
default = null
}