Skip to content
Draft
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
16 changes: 8 additions & 8 deletions network.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ resource "openstack_networking_network_v2" "networks" {
shared = lookup(each.value, "shared", false)
external = lookup(each.value, "external", false)
admin_state_up = lookup(each.value, "admin_state_up", null)
tenant_id = lookup(each.value, "tenant_id", null)
tenant_id = (each.value.project != null ? openstack_identity_project_v3.project[each.value.project].id : each.value.tenant_id)
mtu = lookup(each.value, "mtu", null)
port_security_enabled = lookup(each.value, "port_security_enabled", true)
tags = lookup(each.value, "tags", [])
Expand All @@ -25,11 +25,11 @@ resource "openstack_networking_subnet_v2" "subnets" {
for_each = var.subnets

name = each.key
network_id = each.value.network_id
network_id = (each.value.network != null ? openstack_networking_network_v2.networks[each.value.network].id : each.value.network_id )
region = lookup(each.value, "region", null)
cidr = lookup(each.value, "cidr", null)
ip_version = lookup(each.value, "ip_version", 4) #default can be 4 or 6
tenant_id = lookup(each.value, "tenant_id", null)
tenant_id = (each.value.project != null ? openstack_identity_project_v3.project[each.value.project].id : each.value.tenant_id )
gateway_ip = lookup(each.value, "gateway_ip", null)
enable_dhcp = lookup(each.value, "enable_dhcp", true)
dns_nameservers = lookup(each.value, "dns_nameservers", [])
Expand All @@ -55,24 +55,24 @@ resource "openstack_networking_router_v2" "routers" {
region = lookup(each.value, "region", null)
external_network_id = lookup(each.value, "external_network_id", null)
admin_state_up = lookup(each.value, "admin_state_up", null)
tenant_id = lookup(each.value, "tenant_id", null)
tenant_id = (each.value.project != null ? openstack_identity_project_v3.project[each.value.project].id : each.value.tenant_id )
tags = lookup(each.value, "tags", [])

dynamic "external_fixed_ip" {
for_each = lookup(each.value, "external_fixed_ip", [])
content {
subnet_id = lookup(external_fixed_ip.value, "subnet_id", null)
ip_address = lookup(external_fixed_ip.value, "ip_address", null)
subnet_id = (each.value.subnet != null ? openstack_networking_subnet_v2.subnets[each.value.subnet].id : each.value.subnet_id)
ip_address = lookup(external_fixed_ip.value, "ip_address", null)
}
}
}

resource "openstack_networking_router_interface_v2" "router_interfaces" {
for_each = var.router_interfaces

router_id = each.value.router_id
router_id = (each.value.router != null ? openstack_networking_router_v2.routers[each.value.router].id : each.value.router_id)
region = lookup(each.value, "region", null)
subnet_id = lookup(each.value, "subnet_id", null)
subnet_id = (each.value.subnet != null ? openstack_networking_subnet_v2.subnets[each.value.subnet].id : each.value.subnet_id)
port_id = lookup(each.value, "port_id", null)
force_destroy = lookup(each.value, "force_destroy", false)
}
11 changes: 9 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ variable "networks" {
shared = optional(bool, false)
external = optional(bool, false)
admin_state_up = optional(bool)
project = optional(string)
tenant_id = optional(string)
mtu = optional(number)
port_security_enabled = optional(bool, true)
Expand All @@ -148,10 +149,12 @@ variable "subnets" {

type = map(
object({
network_id = string
network_id = optional(string)
network = optional(string)
region = optional(string)
cidr = optional(string)
ip_version = optional(number, 4)
project = optional(string)
tenant_id = optional(string)
gateway_ip = optional(string)
enable_dhcp = optional(bool, true)
Expand Down Expand Up @@ -179,11 +182,13 @@ variable "routers" {
region = optional(string)
external_network_id = optional(string)
admin_state_up = optional(bool)
tenant_id = optional(string)
project = optional(string)
tenant_id = optional(string)
tags = optional(list(string), [])

external_fixed_ip = optional(
list(object({
subnet = optional(string)
subnet_id = optional(string)
ip_address = optional(string)
})), []
Expand All @@ -196,6 +201,8 @@ variable "routers" {
variable "router_interfaces"{
type = map(
object({
router = optional(string)
subnet = optional(string)
router_id = optional(string)
region = optional(string)
subnet_id = optional(string)
Expand Down