From 0f94aee91dae91f8a9feba6267a912549930cbc3 Mon Sep 17 00:00:00 2001 From: Maximilian Schlenz Date: Mon, 7 Jul 2025 11:12:30 +0200 Subject: [PATCH] network tf module --- network/main.tf | 23 ++++++++++++++++++++ network/output.tf | 19 +++++++++++++++++ network/providers.tf | 9 ++++++++ network/variables.tf | 50 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+) create mode 100644 network/main.tf create mode 100644 network/output.tf create mode 100644 network/providers.tf create mode 100644 network/variables.tf diff --git a/network/main.tf b/network/main.tf new file mode 100644 index 0000000..f9ca504 --- /dev/null +++ b/network/main.tf @@ -0,0 +1,23 @@ +resource "stackit_network" "this" { + project_id = var.project_id + name = var.name + + ipv4_nameservers = var.ipv4_nameservers + labels = var.labels + + routed = true +} + +resource "stackit_network_interface" "static" { + count = var.static_ipv4 == null ? 0 : 1 + + project_id = var.project_id + network_id = stackit_network.this.network_id + + ipv4 = var.static_ipv4 + labels = var.nic_labels + name = var.nic_name == null ? "${var.name}-nic" : var.nic_name + security = var.nic_security + security_group_ids = var.nic_security ? var.nic_security_group_ids : null + allowed_addresses = var.nic_security ? var.nic_allowed_addresses : null +} diff --git a/network/output.tf b/network/output.tf new file mode 100644 index 0000000..14a3f9c --- /dev/null +++ b/network/output.tf @@ -0,0 +1,19 @@ +output "network_id" { + description = "Network ID" + value = stackit_network.this.network_id +} + +output "network_name" { + description = "Network name" + value = stackit_network.this.name +} + +output "network_interface_id" { + description = "NIC ID" + value = try(stackit_network_interface.static[0].network_interface_id, null) +} + +output "static_ipv4" { + description = "IPv4 address assigned to NIC (null when not used)" + value = var.static_ipv4 +} diff --git a/network/providers.tf b/network/providers.tf new file mode 100644 index 0000000..dd742e3 --- /dev/null +++ b/network/providers.tf @@ -0,0 +1,9 @@ +terraform { + required_version = ">= 1.9.0" + required_providers { + stackit = { + source = "stackitcloud/stackit" + version = "0.56.0" + } + } +} \ No newline at end of file diff --git a/network/variables.tf b/network/variables.tf new file mode 100644 index 0000000..5bbe8e6 --- /dev/null +++ b/network/variables.tf @@ -0,0 +1,50 @@ +variable "project_id" { + type = string +} + +variable "name" { + type = string +} + +variable "ipv4_nameservers" { + type = list(string) + default = [] +} + +variable "labels" { + type = map(string) + default = {} +} + +variable "static_ipv4" { + type = string + description = "If set, a NIC will be created with this IPv4." + default = null +} + +variable "nic_name" { + type = string + default = null +} + +variable "nic_allowed_addresses" { + type = list(string) + description = "Additional CIDR blocks for NIC" + default = [] +} + +variable "nic_labels" { + type = map(string) + default = {} +} + +variable "nic_security" { + type = bool + default = true +} + +variable "nic_security_group_ids" { + type = list(string) + description = "nic_security must be set to true" + default = [] +}