Skip to content

Commit 6a4eff3

Browse files
authored
Add Variable for dynamic dns component lookup (#1094)
1 parent 020dc81 commit 6a4eff3

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

modules/eks/external-dns/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ components:
4545
# aws:
4646
# batchChangeSize: 1000
4747
chart_values: {}
48+
# Extra hosted zones to lookup and support by component name
49+
dns_components:
50+
- component: dns-primary
51+
- component: dns-delegated
52+
- component: dns-delegated/abc
53+
- component: dns-delegated/123
54+
environment: "gbl" # Optional (default "gbl")
4855
```
4956
5057
<!-- prettier-ignore-start -->
@@ -68,6 +75,7 @@ components:
6875
6976
| Name | Source | Version |
7077
|------|--------|---------|
78+
| <a name="module_additional_dns_components"></a> [additional\_dns\_components](#module\_additional\_dns\_components) | cloudposse/stack-config/yaml//modules/remote-state | 1.5.0 |
7179
| <a name="module_dns_gbl_delegated"></a> [dns\_gbl\_delegated](#module\_dns\_gbl\_delegated) | cloudposse/stack-config/yaml//modules/remote-state | 1.5.0 |
7280
| <a name="module_dns_gbl_primary"></a> [dns\_gbl\_primary](#module\_dns\_gbl\_primary) | cloudposse/stack-config/yaml//modules/remote-state | 1.5.0 |
7381
| <a name="module_eks"></a> [eks](#module\_eks) | cloudposse/stack-config/yaml//modules/remote-state | 1.5.0 |
@@ -100,6 +108,7 @@ components:
100108
| <a name="input_create_namespace"></a> [create\_namespace](#input\_create\_namespace) | Create the namespace if it does not yet exist. Defaults to `false`. | `bool` | `null` | no |
101109
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
102110
| <a name="input_descriptor_formats"></a> [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.<br>Map of maps. Keys are names of descriptors. Values are maps of the form<br>`{<br> format = string<br> labels = list(string)<br>}`<br>(Type is `any` so the map values can later be enhanced to provide additional options.)<br>`format` is a Terraform format string to be passed to the `format()` function.<br>`labels` is a list of labels, in order, to pass to `format()` function.<br>Label values will be normalized before being passed to `format()` so they will be<br>identical to how they appear in `id`.<br>Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no |
111+
| <a name="input_dns_components"></a> [dns\_components](#input\_dns\_components) | A list of additional DNS components to search for ZoneIDs | <pre>list(object({<br> component = string,<br> environment = optional(string)<br> }))</pre> | `[]` | no |
103112
| <a name="input_dns_gbl_delegated_environment_name"></a> [dns\_gbl\_delegated\_environment\_name](#input\_dns\_gbl\_delegated\_environment\_name) | The name of the environment where global `dns_delegated` is provisioned | `string` | `"gbl"` | no |
104113
| <a name="input_dns_gbl_primary_environment_name"></a> [dns\_gbl\_primary\_environment\_name](#input\_dns\_gbl\_primary\_environment\_name) | The name of the environment where global `dns_primary` is provisioned | `string` | `"gbl"` | no |
105114
| <a name="input_eks_component_name"></a> [eks\_component\_name](#input\_eks\_component\_name) | The name of the eks component | `string` | `"eks/cluster"` | no |

modules/eks/external-dns/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ locals {
99
txt_prefix = var.txt_prefix != "" ? format("%s-", local.txt_owner) : ""
1010
zone_ids = compact(concat(
1111
values(module.dns_gbl_delegated.outputs.zones)[*].zone_id,
12-
values(module.dns_gbl_primary.outputs.zones)[*].zone_id
12+
values(module.dns_gbl_primary.outputs.zones)[*].zone_id,
13+
flatten([for k, v in module.additional_dns_components : [for i, j in v.outputs.zones : j.zone_id]])
1314
))
1415
}
1516

modules/eks/external-dns/remote-state.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,14 @@ module "dns_gbl_primary" {
3636
zones = {}
3737
}
3838
}
39+
40+
module "additional_dns_components" {
41+
for_each = { for obj in var.dns_components : obj.component => obj }
42+
source = "cloudposse/stack-config/yaml//modules/remote-state"
43+
version = "1.5.0"
44+
45+
component = each.value.component
46+
environment = coalesce(each.value.environment, "gbl")
47+
48+
context = module.this.context
49+
}

modules/eks/external-dns/variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ variable "dns_gbl_primary_environment_name" {
132132
default = "gbl"
133133
}
134134

135+
136+
variable "dns_components" {
137+
type = list(object({
138+
component = string,
139+
environment = optional(string)
140+
}))
141+
description = "A list of additional DNS components to search for ZoneIDs"
142+
default = []
143+
}
144+
135145
variable "publish_internal_services" {
136146
type = bool
137147
description = "Allow external-dns to publish DNS records for ClusterIP services"

0 commit comments

Comments
 (0)