Skip to content

Commit dc414ff

Browse files
mahauberCopilot
andcommitted
feat: add DNS zone management to hub-spoke example and update related modules
Co-authored-by: Copilot <copilot@github.com>
1 parent 3f99e3d commit dc414ff

10 files changed

Lines changed: 72 additions & 34 deletions

File tree

examples/02-hub-spoke/main.tf

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ module "connectivity_global" {
6161
parent_container_id = module.governance.folder_container_ids["platform"]
6262
organization_id = var.organization_id
6363
labels = var.labels
64+
dns_zones = var.dns_zones
6465
}
6566

6667
#############################
@@ -72,7 +73,7 @@ module "connectivity_regional" {
7273

7374
project_id = module.connectivity_global.project_id
7475
organization_id = var.organization_id
75-
network_area_name = var.network_area_name
76+
network_area_name = "${var.company_code}-pltfm-hub-prod"
7677
network_ranges = var.network_ranges
7778
transfer_network_range = var.transfer_network_range
7879
min_prefix_length = var.min_prefix_length
@@ -122,14 +123,15 @@ module "landing_zone" {
122123
source = "../../modules/landing-zone"
123124
for_each = var.landing_zones
124125

125-
organization_id = var.organization_id
126-
parent_container_id = each.value.corporate ? module.governance.folder_container_ids["landing_zones_corporate"] : module.governance.folder_container_ids["landing_zones_public"]
127-
naming_pattern = "${var.company_code}-lz-${each.value.project_code}-${each.value.env}"
128-
network_area_id = each.value.corporate ? module.connectivity_regional.network_area_id : null
129-
owner_email = each.value.owner_email
130-
labels = var.labels
131-
role_assignments = each.value.role_assignments
132-
network_prefix_length = each.value.network_prefix_length
133-
custom_roles = each.value.custom_roles
134-
firewall_next_hop_ip = module.connectivity_regional.firewall_next_hop_ip
126+
organization_id = var.organization_id
127+
parent_container_id = each.value.corporate ? module.governance.folder_container_ids["landing_zones_corporate"] : module.governance.folder_container_ids["landing_zones_public"]
128+
naming_pattern = "${var.company_code}-lz-${each.value.project_code}-${each.value.env}"
129+
dns_zone_name = "${each.value.project_code}.${each.value.env}.${var.region}.${values(module.connectivity_global.dns_zone_dns_names)[0]}"
130+
network_area_id = each.value.corporate ? module.connectivity_regional.network_area_id : null
131+
owner_email = each.value.owner_email
132+
labels = var.labels
133+
role_assignments = each.value.role_assignments
134+
network_prefix_length = each.value.network_prefix_length
135+
custom_roles = each.value.custom_roles
136+
firewall_next_hop_ip = module.connectivity_regional.firewall_next_hop_ip
135137
}

examples/02-hub-spoke/outputs.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ output "landing_zone_projects" {
4141
description = "Map of landing zone project IDs."
4242
value = {
4343
for k, v in module.landing_zone : k => {
44-
project_id = v.project_id
45-
project_name = v.project_name
44+
project_id = v.project_id
45+
project_name = v.project_name
46+
dns_zone_name = v.dns_zone_dns_name
4647
}
4748
}
4849
}

examples/02-hub-spoke/terraform.tfvars

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,12 @@ organization_auditors = [
2828
"auditor@example.com"
2929
]
3030

31-
###########################
32-
## CONNECTIVITY - GLOBAL ##
33-
###########################
34-
35-
#############################
36-
## CONNECTIVITY - REGIONAL ##
37-
#############################
38-
39-
# Name of the network area for this region
40-
network_area_name = "corporate"
31+
# DNS zones managed in the connectivity project
32+
dns_zones = {
33+
"prodyna" = {
34+
dns_name = "prodyna.stackit.run"
35+
}
36+
}
4137

4238
# IP ranges that will be sliced into per-project subnets
4339
network_ranges = [

examples/02-hub-spoke/variables.tf

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,24 @@ variable "devops_enabled" {
5252
default = true
5353
}
5454

55-
###########################
56-
## CONNECTIVITY - GLOBAL ##
57-
###########################
55+
variable "dns_zones" {
56+
type = map(object({
57+
dns_name = string
58+
name = optional(string, null)
59+
contact_email = optional(string, null)
60+
type = optional(string, "primary")
61+
acl = optional(string, null)
62+
description = optional(string, null)
63+
default_ttl = optional(number, 3600)
64+
}))
65+
description = "Map of DNS zone keys to DNS zone configuration. Name defaults to dns_name if not set."
66+
default = {}
67+
}
5868

5969
#############################
6070
## CONNECTIVITY - REGIONAL ##
6171
#############################
6272

63-
variable "network_area_name" {
64-
type = string
65-
description = "Name of the network area for this region."
66-
}
67-
6873
variable "network_ranges" {
6974
type = list(object({ prefix = string }))
7075
description = "IP ranges that will be sliced into per-project subnets."

modules/connectivity-global/2-dns-zones.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ resource "stackit_dns_zone" "this" {
22
for_each = var.dns_zones
33

44
project_id = stackit_resourcemanager_project.this.project_id
5-
name = each.value.name
5+
name = each.value.name != null ? each.value.name : each.value.dns_name
66
dns_name = each.value.dns_name
77
contact_email = each.value.contact_email
88
type = each.value.type

modules/connectivity-global/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ output "project_name" {
1616
output "dns_zone_ids" {
1717
description = "Map of DNS zone keys to their zone IDs"
1818
value = { for k, z in stackit_dns_zone.this : k => z.zone_id }
19+
}
20+
21+
output "dns_zone_dns_names" {
22+
description = "Map of DNS zone keys to their DNS names"
23+
value = { for k, z in stackit_dns_zone.this : k => z.dns_name }
1924
}

modules/connectivity-global/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ variable "role_assignments" {
4141

4242
variable "dns_zones" {
4343
type = map(object({
44-
name = string
4544
dns_name = string
45+
name = optional(string, null)
4646
contact_email = optional(string, null)
4747
type = optional(string, "primary")
4848
acl = optional(string, null)
4949
description = optional(string, null)
5050
default_ttl = optional(number, 3600)
5151
}))
52-
description = "Map of DNS zone keys to DNS zone configuration."
52+
description = "Map of DNS zone keys to DNS zone configuration. Name defaults to dns_name if not set."
5353
default = {}
5454
}

modules/landing-zone/7-dns-zone.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
##############
2+
## DNS ZONE ##
3+
##############
4+
5+
resource "stackit_dns_zone" "this" {
6+
count = var.dns_zone_name != null ? 1 : 0
7+
8+
project_id = stackit_resourcemanager_project.this.project_id
9+
name = var.dns_zone_name
10+
dns_name = var.dns_zone_name
11+
type = "primary"
12+
default_ttl = 3600
13+
}

modules/landing-zone/outputs.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,14 @@ output "project_id" {
1111
output "project_name" {
1212
description = "The name of the created STACKIT project."
1313
value = stackit_resourcemanager_project.this.name
14+
}
15+
16+
output "dns_zone_dns_name" {
17+
description = "The DNS name of the landing zone's child DNS zone."
18+
value = var.dns_zone_name != null ? stackit_dns_zone.this[0].dns_name : null
19+
}
20+
21+
output "dns_zone_id" {
22+
description = "The ID of the landing zone's child DNS zone."
23+
value = var.dns_zone_name != null ? stackit_dns_zone.this[0].zone_id : null
1424
}

modules/landing-zone/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,10 @@ variable "ipv4_nameservers" {
7070
type = list(string)
7171
description = "List of IPv4 nameservers for the network."
7272
default = null
73+
}
74+
75+
variable "dns_zone_name" {
76+
type = string
77+
description = "Full DNS zone domain name for this landing zone. Set to null to skip DNS zone creation."
78+
default = null
7379
}

0 commit comments

Comments
 (0)