diff --git a/README.md b/README.md index 3b818cf..fde3b00 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ Functional examples are included in the [examples](./examples/) directory. | name | Zone name, must be unique within the project. | `string` | n/a | yes | | private\_visibility\_config\_networks | List of VPC self links that can see this zone. | `list(string)` | `[]` | no | | project\_id | Project id for the zone. | `string` | n/a | yes | -| recordsets | List of DNS record objects to manage, in the standard terraform dns structure. |
list(object({
name = string
type = string
ttl = number
records = list(string)
}))
| `[]` | no | +| recordsets | List of DNS record objects to manage, in the standard terraform dns structure. |
list(object({
name = string
type = string
ttl = number
records = optional(list(string), null)

routing_policy = optional(object({
wrr = optional(list(object({
weight = number
records = list(string)
})), [])
geo = optional(list(object({
location = string
records = list(string)
})), [])
}))
}))
| `[]` | no | | service\_namespace\_url | The fully qualified or partial URL of the service directory namespace that should be associated with the zone. This should be formatted like https://servicedirectory.googleapis.com/v1/projects/{project}/locations/{location}/namespaces/{namespace_id} or simply projects/{project}/locations/{location}/namespaces/{namespace\_id}. | `string` | `""` | no | | target\_name\_server\_addresses | List of target name servers for forwarding zone. | `list(map(any))` | `[]` | no | | target\_network | Peering network. | `string` | `""` | no | diff --git a/main.tf b/main.tf index eda2c74..c849fd3 100644 --- a/main.tf +++ b/main.tf @@ -206,6 +206,29 @@ resource "google_dns_record_set" "cloud-static-records" { rrdatas = each.value.records + dynamic "routing_policy" { + for_each = toset(each.value.routing_policy != null ? ["create"] : []) + content { + dynamic "wrr" { + for_each = each.value.routing_policy.wrr + iterator = wrr + content { + weight = wrr.value.weight + rrdatas = wrr.value.records + } + } + + dynamic "geo" { + for_each = each.value.routing_policy.geo + iterator = geo + content { + location = geo.value.location + rrdatas = geo.value.records + } + } + } + } + depends_on = [ google_dns_managed_zone.private, google_dns_managed_zone.public, diff --git a/variables.tf b/variables.tf index 099fdcb..8ba804e 100644 --- a/variables.tf +++ b/variables.tf @@ -107,8 +107,20 @@ variable "recordsets" { name = string type = string ttl = number - records = list(string) + records = optional(list(string), null) + + routing_policy = optional(object({ + wrr = optional(list(object({ + weight = number + records = list(string) + })), []) + geo = optional(list(object({ + location = string + records = list(string) + })), []) + })) })) + description = "List of DNS record objects to manage, in the standard terraform dns structure." default = [] }