Skip to content

Commit

Permalink
feat: add force_destroy variable for zones (#29)
Browse files Browse the repository at this point in the history
Co-authored-by: Christian Groschupp <[email protected]>
  • Loading branch information
cgroschupp and Christian Groschupp authored Jun 23, 2021
1 parent 53955cb commit 8bb8746
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 30 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Functional examples are included in the [examples](./examples/) directory.
| description | zone description (shown in console) | `string` | `"Managed by Terraform"` | no |
| dnssec\_config | Object containing : kind, non\_existence, state. Please see https://www.terraform.io/docs/providers/google/r/dns_managed_zone.html#dnssec_config for futhers details | `any` | `{}` | no |
| domain | Zone domain, must end with a period. | `string` | n/a | yes |
| force\_destroy | Set this true to delete all records in the zone. | `bool` | `false` | no |
| labels | A set of key/value label pairs to assign to this ManagedZone | `map(any)` | `{}` | no |
| 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 |
Expand Down
64 changes: 34 additions & 30 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ locals {
}

resource "google_dns_managed_zone" "peering" {
count = var.type == "peering" ? 1 : 0
provider = google-beta
project = var.project_id
name = var.name
dns_name = var.domain
description = var.description
labels = var.labels
visibility = "private"
count = var.type == "peering" ? 1 : 0
provider = google-beta
project = var.project_id
name = var.name
dns_name = var.domain
description = var.description
labels = var.labels
visibility = "private"
force_destroy = var.force_destroy

private_visibility_config {
dynamic "networks" {
Expand All @@ -45,14 +46,15 @@ resource "google_dns_managed_zone" "peering" {
}

resource "google_dns_managed_zone" "forwarding" {
count = var.type == "forwarding" ? 1 : 0
provider = google-beta
project = var.project_id
name = var.name
dns_name = var.domain
description = var.description
labels = var.labels
visibility = "private"
count = var.type == "forwarding" ? 1 : 0
provider = google-beta
project = var.project_id
name = var.name
dns_name = var.domain
description = var.description
labels = var.labels
visibility = "private"
force_destroy = var.force_destroy

private_visibility_config {
dynamic "networks" {
Expand All @@ -75,13 +77,14 @@ resource "google_dns_managed_zone" "forwarding" {
}

resource "google_dns_managed_zone" "private" {
count = var.type == "private" ? 1 : 0
project = var.project_id
name = var.name
dns_name = var.domain
description = var.description
labels = var.labels
visibility = "private"
count = var.type == "private" ? 1 : 0
project = var.project_id
name = var.name
dns_name = var.domain
description = var.description
labels = var.labels
visibility = "private"
force_destroy = var.force_destroy

private_visibility_config {
dynamic "networks" {
Expand All @@ -94,13 +97,14 @@ resource "google_dns_managed_zone" "private" {
}

resource "google_dns_managed_zone" "public" {
count = var.type == "public" ? 1 : 0
project = var.project_id
name = var.name
dns_name = var.domain
description = var.description
labels = var.labels
visibility = "public"
count = var.type == "public" ? 1 : 0
project = var.project_id
name = var.name
dns_name = var.domain
description = var.description
labels = var.labels
visibility = "public"
force_destroy = var.force_destroy

dynamic "dnssec_config" {
for_each = var.dnssec_config == {} ? [] : [var.dnssec_config]
Expand Down
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ variable "default_key_specs_zone" {
default = {}
}

variable "force_destroy" {
description = "Set this true to delete all records in the zone."
default = false
type = bool
}

###############################################################################
# record variables #
Expand Down

0 comments on commit 8bb8746

Please sign in to comment.