feat: add variable for configuring public DNS upstreams on subnets

This commit is contained in:
Bertrand Lanson 2024-04-14 00:24:12 +02:00
parent 0f61134f89
commit 98594d22b9
3 changed files with 37 additions and 35 deletions

View File

@ -63,6 +63,7 @@ No modules.
| <a name="input_project_domain"></a> [project_domain](#input_project_domain) | The domain where this project will be created | `string` | `"default"` | no | | <a name="input_project_domain"></a> [project_domain](#input_project_domain) | The domain where this project will be created | `string` | `"default"` | no |
| <a name="input_project_name"></a> [project_name](#input_project_name) | The name of the project | `string` | n/a | yes | | <a name="input_project_name"></a> [project_name](#input_project_name) | The name of the project | `string` | n/a | yes |
| <a name="input_project_tags"></a> [project_tags](#input_project_tags) | The tags to append to this project | `list(string)` | `[]` | no | | <a name="input_project_tags"></a> [project_tags](#input_project_tags) | The tags to append to this project | `list(string)` | `[]` | no |
| <a name="input_public_nameservers"></a> [public_nameservers](#input_public_nameservers) | A list of public DNS servers to upstreams requests to in your subnets.<br>This is not necessary if your openstack deployment already has configured default upstreams for neutron. | `list(string)` | `[]` | no |
| <a name="input_public_subnetpool_id"></a> [public_subnetpool_id](#input_public_subnetpool_id) | The id of the subnetpool to create the public (first 2 tier) networks from.<br>Since this module can route private subnets to the backbone, it needs to make sure it's not creating overlapping subnets. | `string` | `null` | no | | <a name="input_public_subnetpool_id"></a> [public_subnetpool_id](#input_public_subnetpool_id) | The id of the subnetpool to create the public (first 2 tier) networks from.<br>Since this module can route private subnets to the backbone, it needs to make sure it's not creating overlapping subnets. | `string` | `null` | no |
| <a name="input_subnetpool_cidr_blocks"></a> [subnetpool_cidr_blocks](#input_subnetpool_cidr_blocks) | The CIDR block for the subnet pool | `list(string)` | <pre>[<br> "192.168.0.0/21"<br>]</pre> | no | | <a name="input_subnetpool_cidr_blocks"></a> [subnetpool_cidr_blocks](#input_subnetpool_cidr_blocks) | The CIDR block for the subnet pool | `list(string)` | <pre>[<br> "192.168.0.0/21"<br>]</pre> | no |

51
main.tf
View File

@ -58,36 +58,39 @@ resource "openstack_networking_network_v2" "database" {
} }
resource "openstack_networking_subnet_v2" "frontend" { resource "openstack_networking_subnet_v2" "frontend" {
count = var.architecture_tiers > 0 ? 1 : 0 count = var.architecture_tiers > 0 ? 1 : 0
name = "${var.project_name}-frontend-subnet-${count.index + 1}" name = "${var.project_name}-frontend-subnet-${count.index + 1}"
description = "Terraform managed." description = "Terraform managed."
tenant_id = data.openstack_identity_project_v3.this.id tenant_id = data.openstack_identity_project_v3.this.id
network_id = openstack_networking_network_v2.frontend[0].id network_id = openstack_networking_network_v2.frontend[0].id
prefix_length = var.frontend_subnet_prefix_len prefix_length = var.frontend_subnet_prefix_len
ip_version = 4 ip_version = 4
subnetpool_id = var.create_subnetpool ? openstack_networking_subnetpool_v2.this[0].id : var.public_subnetpool_id subnetpool_id = var.create_subnetpool ? openstack_networking_subnetpool_v2.this[0].id : var.public_subnetpool_id
dns_nameservers = var.public_nameservers
} }
resource "openstack_networking_subnet_v2" "backend" { resource "openstack_networking_subnet_v2" "backend" {
count = var.architecture_tiers > 1 ? 1 : 0 count = var.architecture_tiers > 1 ? 1 : 0
name = "${var.project_name}-backend-subnet-${count.index + 1}" name = "${var.project_name}-backend-subnet-${count.index + 1}"
description = "Terraform managed." description = "Terraform managed."
tenant_id = data.openstack_identity_project_v3.this.id tenant_id = data.openstack_identity_project_v3.this.id
network_id = openstack_networking_network_v2.backend[0].id network_id = openstack_networking_network_v2.backend[0].id
prefix_length = var.backend_subnet_prefix_len prefix_length = var.backend_subnet_prefix_len
ip_version = 4 ip_version = 4
subnetpool_id = var.create_subnetpool ? openstack_networking_subnetpool_v2.this[0].id : var.public_subnetpool_id subnetpool_id = var.create_subnetpool ? openstack_networking_subnetpool_v2.this[0].id : var.public_subnetpool_id
dns_nameservers = var.public_nameservers
} }
resource "openstack_networking_subnet_v2" "database" { resource "openstack_networking_subnet_v2" "database" {
count = var.architecture_tiers == 3 ? 1 : 0 count = var.architecture_tiers == 3 ? 1 : 0
name = "${var.project_name}-database-subnet-${count.index + 1}" name = "${var.project_name}-database-subnet-${count.index + 1}"
description = "Terraform managed." description = "Terraform managed."
tenant_id = data.openstack_identity_project_v3.this.id tenant_id = data.openstack_identity_project_v3.this.id
network_id = openstack_networking_network_v2.database[0].id network_id = openstack_networking_network_v2.database[0].id
prefix_length = var.database_subnet_prefix_len prefix_length = var.database_subnet_prefix_len
ip_version = 4 ip_version = 4
subnetpool_id = var.create_subnetpool ? openstack_networking_subnetpool_v2.this[0].id : var.database_subnetpool_id subnetpool_id = var.create_subnetpool ? openstack_networking_subnetpool_v2.this[0].id : var.database_subnetpool_id
dns_nameservers = var.public_nameservers
} }
#! router #! router

View File

@ -100,6 +100,15 @@ variable "database_subnet_prefix_len" {
} }
} }
variable "public_nameservers" {
type = list(string)
description = <<-EOT
A list of public DNS servers to upstreams requests to in your subnets.
This is not necessary if your openstack deployment already has configured default upstreams for neutron.
EOT
default = []
}
#! security variables #! security variables
variable "create_default_secgroups" { variable "create_default_secgroups" {
type = bool type = bool
@ -191,21 +200,10 @@ variable "external_network_id" {
default = null default = null
} }
# variable "external_subnet_id" {
# type = string
# description = "The id of the external subnet to connect the frontend router to."
# default = null
# }
locals { locals {
validate_external_network_id = ( validate_external_network_id = (
var.architecture_tiers > 0 && var.architecture_tiers > 0 &&
var.attach_to_external && var.attach_to_external &&
var.external_network_id == null var.external_network_id == null
) ? tobool("Please pass in the external network ID to attach the frontend router to.") : true ) ? tobool("Please pass in the external network ID to attach the frontend router to.") : true
# validate_external_subnet_id = (
# var.architecture_tiers > 0 &&
# var.attach_to_external &&
# var.external_subnet_id == null
# ) ? tobool("Please pass in the external subnet ID to attach the frontend router to.") : true
} }