custom static ip nic
This commit is contained in:
parent
0f94aee91d
commit
c335e50eff
3 changed files with 80 additions and 25 deletions
|
|
@ -2,21 +2,29 @@ resource "stackit_network" "this" {
|
||||||
project_id = var.project_id
|
project_id = var.project_id
|
||||||
name = var.name
|
name = var.name
|
||||||
|
|
||||||
ipv4_nameservers = var.ipv4_nameservers
|
ipv4_gateway = var.routed == false ? var.ipv4_gateway : null
|
||||||
labels = var.labels
|
ipv4_nameservers = var.ipv4_nameservers
|
||||||
|
ipv4_prefix = var.ipv4_prefix
|
||||||
routed = true
|
ipv4_prefix_length = var.ipv4_prefix_length
|
||||||
|
ipv6_gateway = var.routed == false ? var.ipv6_gateway : null
|
||||||
|
ipv6_nameservers = var.ipv6_nameservers
|
||||||
|
ipv6_prefix = var.ipv6_prefix
|
||||||
|
ipv6_prefix_length = var.ipv6_prefix_length
|
||||||
|
labels = var.labels
|
||||||
|
no_ipv4_gateway = var.no_ipv4_gateway
|
||||||
|
no_ipv6_gateway = var.no_ipv6_gateway
|
||||||
|
routed = var.routed
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "stackit_network_interface" "static" {
|
resource "stackit_network_interface" "static" {
|
||||||
count = var.static_ipv4 == null ? 0 : 1
|
count = var.nic_ipv4 == null ? 0 : 1
|
||||||
|
|
||||||
project_id = var.project_id
|
|
||||||
network_id = stackit_network.this.network_id
|
network_id = stackit_network.this.network_id
|
||||||
|
project_id = var.project_id
|
||||||
|
|
||||||
ipv4 = var.static_ipv4
|
ipv4 = var.nic_ipv4
|
||||||
labels = var.nic_labels
|
labels = var.nic_labels
|
||||||
name = var.nic_name == null ? "${var.name}-nic" : var.nic_name
|
name = var.nic_name != null ? var.nic_name : "${var.name}-nic"
|
||||||
security = var.nic_security
|
security = var.nic_security
|
||||||
security_group_ids = var.nic_security ? var.nic_security_group_ids : null
|
security_group_ids = var.nic_security ? var.nic_security_group_ids : null
|
||||||
allowed_addresses = var.nic_security ? var.nic_allowed_addresses : null
|
allowed_addresses = var.nic_security ? var.nic_allowed_addresses : null
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ output "network_interface_id" {
|
||||||
value = try(stackit_network_interface.static[0].network_interface_id, null)
|
value = try(stackit_network_interface.static[0].network_interface_id, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
output "static_ipv4" {
|
output "nic_ipv4_list" {
|
||||||
description = "IPv4 address assigned to NIC (null when not used)"
|
value = try(stackit_network_interface.static[*].ipv4, null)
|
||||||
value = var.static_ipv4
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,31 +6,74 @@ variable "name" {
|
||||||
type = string
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
variable "ipv4_gateway" {
|
||||||
|
type = string
|
||||||
|
default = null
|
||||||
|
}
|
||||||
|
|
||||||
variable "ipv4_nameservers" {
|
variable "ipv4_nameservers" {
|
||||||
type = list(string)
|
type = list(string)
|
||||||
default = []
|
default = []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
variable "ipv4_prefix" {
|
||||||
|
type = string # CIDR, only for NON-routed nets
|
||||||
|
default = null
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "ipv4_prefix_length" {
|
||||||
|
type = number # e.g. 24
|
||||||
|
default = null
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "ipv6_gateway" {
|
||||||
|
type = string
|
||||||
|
default = null
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "ipv6_nameservers" {
|
||||||
|
type = list(string)
|
||||||
|
default = []
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "ipv6_prefix" {
|
||||||
|
type = string
|
||||||
|
default = null
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "ipv6_prefix_length" {
|
||||||
|
type = number
|
||||||
|
default = null
|
||||||
|
}
|
||||||
|
|
||||||
variable "labels" {
|
variable "labels" {
|
||||||
type = map(string)
|
type = map(string)
|
||||||
default = {}
|
default = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "static_ipv4" {
|
variable "no_ipv4_gateway" {
|
||||||
type = string
|
type = bool
|
||||||
description = "If set, a NIC will be created with this IPv4."
|
default = false
|
||||||
default = null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "nic_name" {
|
variable "no_ipv6_gateway" {
|
||||||
type = string
|
type = bool
|
||||||
default = null
|
default = false
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "routed" {
|
||||||
|
type = bool
|
||||||
|
default = true
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "nic_allowed_addresses" {
|
variable "nic_allowed_addresses" {
|
||||||
type = list(string)
|
type = list(string)
|
||||||
description = "Additional CIDR blocks for NIC"
|
default = []
|
||||||
default = []
|
}
|
||||||
|
|
||||||
|
variable "nic_ipv4" {
|
||||||
|
type = string
|
||||||
|
default = null
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "nic_labels" {
|
variable "nic_labels" {
|
||||||
|
|
@ -38,13 +81,18 @@ variable "nic_labels" {
|
||||||
default = {}
|
default = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
variable "nic_name" {
|
||||||
|
type = string
|
||||||
|
default = null
|
||||||
|
}
|
||||||
|
|
||||||
variable "nic_security" {
|
variable "nic_security" {
|
||||||
type = bool
|
type = bool
|
||||||
default = true
|
default = false
|
||||||
|
nullable = false
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "nic_security_group_ids" {
|
variable "nic_security_group_ids" {
|
||||||
type = list(string)
|
type = list(string)
|
||||||
description = "nic_security must be set to true"
|
default = []
|
||||||
default = []
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue