Skip to content

Commit

Permalink
Added iam for DNS managed zone to dns module
Browse files Browse the repository at this point in the history
  • Loading branch information
apichick committed Jun 19, 2023
1 parent a68a3b5 commit ddfab0a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
25 changes: 16 additions & 9 deletions modules/dns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ module "private-dns" {
"A localhost" = { records = ["127.0.0.1"] }
"A myhost" = { ttl = 600, records = ["10.0.0.120"] }
}
iam = {
"roles/dns.admin" = ["group:[email protected]"]
}
}
# tftest modules=1 resources=3 inventory=private-zone.yaml
# tftest modules=1 resources=4 inventory=private-zone.yaml
```

### Forwarding Zone
Expand Down Expand Up @@ -114,8 +117,11 @@ module "public-dns" {
recordsets = {
"A myhost" = { ttl = 300, records = ["127.0.0.1"] }
}
iam = {
"roles/dns.admin" = ["group:[email protected]"]
}
}
# tftest modules=1 resources=3 inventory=public-zone.yaml
# tftest modules=1 resources=4 inventory=public-zone.yaml
```
<!-- BEGIN TFDOC -->

Expand All @@ -124,18 +130,19 @@ module "public-dns" {
| name | description | type | required | default |
|---|---|:---:|:---:|:---:|
| [domain](variables.tf#L54) | Zone domain, must end with a period. | <code>string</code> || |
| [name](variables.tf#L72) | Zone name, must be unique within the project. | <code>string</code> || |
| [project_id](variables.tf#L83) | Project id for the zone. | <code>string</code> || |
| [name](variables.tf#L78) | Zone name, must be unique within the project. | <code>string</code> || |
| [project_id](variables.tf#L89) | Project id for the zone. | <code>string</code> || |
| [client_networks](variables.tf#L21) | List of VPC self links that can see this zone. | <code>list&#40;string&#41;</code> | | <code>&#91;&#93;</code> |
| [description](variables.tf#L28) | Domain description. | <code>string</code> | | <code>&#34;Terraform managed.&#34;</code> |
| [dnssec_config](variables.tf#L34) | DNSSEC configuration for this zone. | <code title="object&#40;&#123;&#10; non_existence &#61; optional&#40;string, &#34;nsec3&#34;&#41;&#10; state &#61; string&#10; key_signing_key &#61; optional&#40;object&#40;&#10; &#123; algorithm &#61; string, key_length &#61; number &#125;&#41;,&#10; &#123; algorithm &#61; &#34;rsasha256&#34;, key_length &#61; 2048 &#125;&#10; &#41;&#10; zone_signing_key &#61; optional&#40;object&#40;&#10; &#123; algorithm &#61; string, key_length &#61; number &#125;&#41;,&#10; &#123; algorithm &#61; &#34;rsasha256&#34;, key_length &#61; 1024 &#125;&#10; &#41;&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code title="&#123;&#10; state &#61; &#34;off&#34;&#10;&#125;">&#123;&#8230;&#125;</code> |
| [enable_logging](variables.tf#L59) | Enable query logging for this zone. | <code>bool</code> | | <code>false</code> |
| [forwarders](variables.tf#L66) | Map of {IPV4_ADDRESS => FORWARDING_PATH} for 'forwarding' zone types. Path can be 'default', 'private', or null for provider default. | <code>map&#40;string&#41;</code> | | <code>&#123;&#125;</code> |
| [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','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> |
| [iam](variables.tf#L72) | IAM bindings in {ROLE => [MEMBERS]} format. | <code>map&#40;list&#40;string&#41;&#41;</code> | | <code>null</code> |
| [peer_network](variables.tf#L83) | Peering network self link, only valid for 'peering' zone types. | <code>string</code> | | <code>null</code> |
| [recordsets](variables.tf#L94) | 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#L129) | Service directory namespace id (URL), only valid for 'service-directory' zone types. | <code>string</code> | | <code>null</code> |
| [type](variables.tf#L135) | 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#L145) | Create zone. When set to false, uses a data source to reference existing zone. | <code>bool</code> | | <code>true</code> |

## Outputs

Expand Down
10 changes: 10 additions & 0 deletions modules/dns/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,16 @@ resource "google_dns_managed_zone" "public" {
}
}

resource "google_dns_managed_zone_iam_binding" "iam_bindings" {
for_each = coalesce(var.iam, {})
project = var.project_id
managed_zone = (var.type == "public"
? google_dns_managed_zone.public[0].name
: google_dns_managed_zone.non-public[0].name)
role = each.key
members = each.value
}

data "google_dns_keys" "dns_keys" {
count = var.zone_create && (var.dnssec_config == {} || var.type != "public") ? 0 : 1
managed_zone = local.zone.id
Expand Down
6 changes: 6 additions & 0 deletions modules/dns/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ variable "forwarders" {
default = {}
}

variable "iam" {
description = "IAM bindings in {ROLE => [MEMBERS]} format."
type = map(list(string))
default = null
}

variable "name" {
description = "Zone name, must be unique within the project."
type = string
Expand Down
1 change: 1 addition & 0 deletions tests/modules/dns/examples/private-zone.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ values:
counts:
google_dns_managed_zone: 1
google_dns_record_set: 2
google_dns_managed_zone_iam_binding: 1
3 changes: 2 additions & 1 deletion tests/modules/dns/examples/public-zone.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ counts:
google_dns_keys: 1
google_dns_managed_zone: 1
google_dns_record_set: 1
google_dns_managed_zone_iam_binding: 1
modules: 1
resources: 3
resources: 4

outputs: {}

0 comments on commit ddfab0a

Please sign in to comment.