Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data google_dns_managed_zone errors if zone doesn't exist #9817

Closed
jimsnab opened this issue Aug 16, 2021 · 1 comment · Fixed by GoogleCloudPlatform/magic-modules#5127, hashicorp/terraform-provider-google-beta#3559 or #9898
Assignees
Labels
bug forward/review In review; remove label to forward service/cloud-dns

Comments

@jimsnab
Copy link

jimsnab commented Aug 16, 2021

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request.
  • Please do not leave +1 or me too comments, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.
  • If an issue is assigned to the modular-magician user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned to hashibot, a community member has claimed the issue already.

Terraform Version

Terraform v1.0.4
on linux_amd64
+ provider registry.terraform.io/hashicorp/google v3.77.0
+ provider registry.terraform.io/hashicorp/helm v2.2.0
+ provider registry.terraform.io/hashicorp/kubernetes v2.4.0

Affected Resource(s)

  • data source google_dns_managed_zone

Terraform Configuration Files

# External DNS zone
data "google_dns_managed_zone" "external_zone" {
  name        = local.zone_name
  project     = var.project_id 
}

resource "google_dns_managed_zone" "external_zone" {
  count       = (data.google_dns_managed_zone.external_zone.dns_name == null ? 1 : 0)
  dns_name    = "${var.project_name}.${var.domain_name}"
  name        = local.zone_name
  description = "External DNS zone"
}

Debug Output

Panic Output

Expected Behavior

Script creates the zone first time it is run, and does not attempt to create the zone subsequent runs - each run starting from a fresh tfstate file.

Since Terraform lacks a create-if-necessary mechanism, the count is typically used as a workaround. The Google provider is inconsistent in its support for this workaround. For example, data google_kms_key_ring will have its output attributes null if the key ring doesn't exist (and will not error).

google_dns_managed_zone should provide a way to specify the zone should be created if it does not yet exist.

Actual Behavior

The script errors the first time because data google_dns_managed_zone does not support returning nulls as output.

Steps to Reproduce

  1. terraform apply

Important Factoids

This is normally not needed if terraform tfstate file is maintained. However, due to other bugs, we are blocked use terraform destroy, and thus sometimes we need to start a new state file with an environment that has some existing configuration. And therefore we require a way to create-if-missing.

terraform import is a manual and laborious workaround, but does not always work either due to errors for missing dependencies such as providers that haven't yet been established (catch-22).

References

  • #0000
@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2021
@github-actions github-actions bot added forward/review In review; remove label to forward service/cloud-dns labels Jan 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug forward/review In review; remove label to forward service/cloud-dns
Projects
None yet
2 participants