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

ensure dns_keys output freshness #2495

Merged
merged 2 commits into from
Aug 9, 2024

Conversation

nathou
Copy link
Contributor

@nathou nathou commented Aug 9, 2024

When making changes to the dnssec_config of the dns module, the dns_keys output is retrieved before the changes to the dns zone.
Not only this means it takes two terraform apply to converge, but this is an issue when you enable dnssec and expect to find a ds_record in the output (to create a DS recordset).

For example, create a test public zone without dnssec enabled:

module "dns" {
  source     = "[email protected]:GoogleCloudPlatform/cloud-foundation-fabric.git//modules/dns"
  project_id = "my-dns-keys-test-project"
  name       = "my-test-zone"

  zone_config = {
    domain = "testkeys.example.com."
    public = {
      enable_logging = false
    }
  }
}

output "keys" {
  value = module.dns.dns_keys
}

This outputs the following, as expected:

keys = []

Then, enable dnssec:

     public = {
       enable_logging = false
+      dnssec_config = {
+        state = "on"
+      }
     }

After one run, the output changes because the dnssec state variable is now "on", but the keys themselves are null:

keys = [
  {
    "id" = "projects/my-dns-keys-test-project/managedZones/my-test-zone"
    "key_signing_keys" = tolist(null) /* of object */
    "managed_zone" = "projects/my-dns-keys-test-project/managedZones/my-test-zone"
    "project" = "my-dns-keys-test-project"
    "zone_signing_keys" = tolist(null) /* of object */
  },
]

A second run finally updates the output:

keys = [
  {
    "id" = "projects/my-dns-keys-test-project/managedZones/my-test-zone"
    "key_signing_keys" = tolist([
      {
        "algorithm" = "rsasha256"
        "creation_time" = "2024-08-09T12:44:57.244Z"
        "description" = ""
        "digests" = tolist([
          {
            "digest" = "2ECD30852EDE31D95BCBB511DC2701153038255EC0E0B1827AF3A2CFCD121C07"
            "type" = "sha256"
          },
        ])
        "ds_record" = "722 8 2 2ECD30852EDE31D95BCBB511DC2701153038255EC0E0B1827AF3A2CFCD121C07"
        "id" = "0"
        "is_active" = true
[...]
      },
    ])
    "managed_zone" = "projects/my-dns-keys-test-project/managedZones/my-test-zone"
    "project" = "my-dns-keys-test-project"
    "zone_signing_keys" = tolist([
      {
        "algorithm" = "rsasha256"
        "creation_time" = "2024-08-09T12:44:57.430Z"
        "description" = ""
        "digests" = tolist([])
        "id" = "1"
        "is_active" = true
[...]
    ])
  },
]

With the dependency, the dns_keys are retrieved after the zone is modified, and the output contains the keys from the first apply.


Checklist

I applicable, I acknowledge that I have:

  • Read the contributing guide
  • Ran terraform fmt on all modified files
  • Regenerated the relevant README.md files using tools/tfdoc.py
  • Made sure all relevant tests pass

@juliocc juliocc enabled auto-merge (squash) August 9, 2024 14:22
@juliocc juliocc merged commit d5210d5 into GoogleCloudPlatform:master Aug 9, 2024
14 checks passed
@nathou nathou deleted the dns-data-dependency branch August 9, 2024 14:35
nathou added a commit to Echo-analytics/cloud-foundation-fabric that referenced this pull request Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants