Add support for forwarding path to dns module (#171)

* add support for forwarding path to dns module

* update README
This commit is contained in:
Ludovico Magnocavallo
2020-11-20 08:35:58 +01:00
committed by GitHub
parent db444be03b
commit 27aa0aa64c
6 changed files with 35 additions and 14 deletions

View File

@@ -4,7 +4,9 @@ This module allows simple management of Google Cloud DNS zones and records. It s
For DNSSEC configuration, refer to the [`dns_managed_zone` documentation](https://www.terraform.io/docs/providers/google/r/dns_managed_zone.html#dnssec_config).
## Example
## Examples
### Private Zone
```hcl
module "private-dns" {
@@ -21,6 +23,21 @@ module "private-dns" {
# tftest:modules=1:resources=2
```
### Forwarding Zone
```hcl
module "private-dns" {
source = "./modules/dns"
project_id = "myproject"
type = "forwarding"
name = "test-example"
domain = "test.example."
client_networks = [var.vpc.self_link]
forwarders = { "10.0.1.1" = null, "1.2.3.4" = "private" }
}
# tftest:modules=1:resources=1
```
<!-- BEGIN TFDOC -->
## Variables
@@ -34,7 +51,7 @@ module "private-dns" {
| *default_key_specs_zone* | DNSSEC default zone signing specifications: algorithm, key_length, key_type, kind. | <code title="">any</code> | | <code title="">{}</code> |
| *description* | Domain description. | <code title="">string</code> | | <code title="">Terraform managed.</code> |
| *dnssec_config* | DNSSEC configuration: kind, non_existence, state. | <code title="">any</code> | | <code title="">{}</code> |
| *forwarders* | List of target name servers, only valid for 'forwarding' zone types. | <code title="list&#40;string&#41;">list(string)</code> | | <code title="">[]</code> |
| *forwarders* | Map of {IPV4_ADDRESS => FORWARDING_PATH} for 'forwarding' zone types. Path can be 'default', 'private', or null for provider default. | <code title="map&#40;string&#41;">map(string)</code> | | <code title="">{}</code> |
| *peer_network* | Peering network self link, only valid for 'peering' zone types. | <code title="">string</code> | | <code title="">null</code> |
| *recordsets* | List of DNS record objects to manage. | <code title="list&#40;object&#40;&#123;&#10;name &#61; string&#10;type &#61; string&#10;ttl &#61; number&#10;records &#61; list&#40;string&#41;&#10;&#125;&#41;&#41;">list(object({...}))</code> | | <code title="">[]</code> |
| *service_directory_namespace* | Service directory namespace id (URL), only valid for 'service-directory' zone types. | <code title="">string</code> | | <code title="">null</code> |

View File

@@ -44,14 +44,19 @@ resource "google_dns_managed_zone" "non-public" {
dynamic forwarding_config {
for_each = (
var.type == "forwarding" && var.forwarders != null ? [""] : []
var.type == "forwarding" &&
var.forwarders != null &&
length(var.forwarders) > 0
? [""]
: []
)
content {
dynamic "target_name_servers" {
for_each = var.forwarders
iterator = address
iterator = forwarder
content {
ipv4_address = address.value
ipv4_address = forwarder.key
forwarding_path = forwarder.value
}
}
}

View File

@@ -53,11 +53,10 @@ variable "domain" {
type = string
}
# TODO(ludoo): add support for forwarding path attribute
variable "forwarders" {
description = "List of target name servers, only valid for 'forwarding' zone types."
type = list(string)
default = []
description = "Map of {IPV4_ADDRESS => FORWARDING_PATH} for 'forwarding' zone types. Path can be 'default', 'private', or null for provider default."
type = map(string)
default = {}
}
variable "name" {