Skip to content

Commit

Permalink
added reverse lookup feature to module dns #1042 (#1043)
Browse files Browse the repository at this point in the history
* added reverse lookup feature to module dns

* corrected readme example passed tfdoc and tests

Co-authored-by: Ludovico Magnocavallo <[email protected]>
  • Loading branch information
chemapolo and ludoo authored Dec 8, 2022
1 parent 06dc4ea commit 9786dc4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
18 changes: 16 additions & 2 deletions modules/dns/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Google Cloud DNS Module

This module allows simple management of Google Cloud DNS zones and records. It supports creating public, private, forwarding, peering and service directory based zones.
This module allows simple management of Google Cloud DNS zones and records. It supports creating public, private, forwarding, peering, service directory and reverse-managed based zones.

For DNSSEC configuration, refer to the [`dns_managed_zone` documentation](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/dns_managed_zone#dnssec_config).

Expand Down Expand Up @@ -86,6 +86,20 @@ module "private-dns" {
}
# tftest modules=1 resources=4
```

### Reverse Lookup Zone

```hcl
module "private-dns" {
source = "./fabric/modules/dns"
project_id = "myproject"
type = "reverse-managed"
name = "test-example"
domain = "0.0.10.in-addr.arpa."
client_networks = [var.vpc.self_link]
}
# tftest modules=1 resources=1
```
<!-- BEGIN TFDOC -->

## Variables
Expand All @@ -103,7 +117,7 @@ module "private-dns" {
| [peer_network](variables.tf#L77) | Peering network self link, only valid for 'peering' zone types. | <code>string</code> | | <code>null</code> |
| [recordsets](variables.tf#L88) | Map of DNS recordsets in \"type name\" => {ttl, [records]} format. | <code title="map&#40;object&#40;&#123;&#10; ttl &#61; optional&#40;number, 300&#41;&#10; records &#61; optional&#40;list&#40;string&#41;&#41;&#10; geo_routing &#61; optional&#40;list&#40;object&#40;&#123;&#10; location &#61; string&#10; records &#61; list&#40;string&#41;&#10; &#125;&#41;&#41;&#41;&#10; wrr_routing &#61; optional&#40;list&#40;object&#40;&#123;&#10; weight &#61; number&#10; records &#61; list&#40;string&#41;&#10; &#125;&#41;&#41;&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [service_directory_namespace](variables.tf#L123) | Service directory namespace id (URL), only valid for 'service-directory' zone types. | <code>string</code> | | <code>null</code> |
| [type](variables.tf#L129) | Type of zone to create, valid values are 'public', 'private', 'forwarding', 'peering', 'service-directory'. | <code>string</code> | | <code>&#34;private&#34;</code> |
| [type](variables.tf#L129) | Type of zone to create, valid values are 'public', 'private', 'forwarding', 'peering', 'service-directory','reverse-managed'. | <code>string</code> | | <code>&#34;private&#34;</code> |
| [zone_create](variables.tf#L139) | Create zone. When set to false, uses a data source to reference existing zone. | <code>bool</code> | | <code>true</code> |

## Outputs
Expand Down
15 changes: 8 additions & 7 deletions modules/dns/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ locals {
}

resource "google_dns_managed_zone" "non-public" {
count = (var.zone_create && var.type != "public") ? 1 : 0
provider = google-beta
project = var.project_id
name = var.name
dns_name = var.domain
description = var.description
visibility = "private"
count = (var.zone_create && var.type != "public") ? 1 : 0
provider = google-beta
project = var.project_id
name = var.name
dns_name = var.domain
description = var.description
visibility = "private"
reverse_lookup = (var.type == "reverse-managed")

dynamic "forwarding_config" {
for_each = (
Expand Down
6 changes: 3 additions & 3 deletions modules/dns/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ variable "service_directory_namespace" {
}

variable "type" {
description = "Type of zone to create, valid values are 'public', 'private', 'forwarding', 'peering', 'service-directory'."
description = "Type of zone to create, valid values are 'public', 'private', 'forwarding', 'peering', 'service-directory','reverse-managed'."
type = string
default = "private"
validation {
condition = contains(["public", "private", "forwarding", "peering", "service-directory"], var.type)
error_message = "Zone must be one of 'public', 'private', 'forwarding', 'peering', 'service-directory'."
condition = contains(["public", "private", "forwarding", "peering", "service-directory", "reverse-managed"], var.type)
error_message = "Zone must be one of 'public', 'private', 'forwarding', 'peering', 'service-directory','reverse-managed'."
}
}

Expand Down

0 comments on commit 9786dc4

Please sign in to comment.