From 24cbb02bff88641d76a8a30a301fe41f5c70f33a Mon Sep 17 00:00:00 2001 From: beatz174-bit Date: Wed, 13 May 2026 06:40:25 +1000 Subject: [PATCH] Fix Dynu inventory by removing unsupported regexreplace usage --- infrastructure/terraform/dynu/README.md | 31 ++++++++++++++++++++++ infrastructure/terraform/dynu/inventory.tf | 13 --------- infrastructure/terraform/dynu/outputs.tf | 6 ++--- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/infrastructure/terraform/dynu/README.md b/infrastructure/terraform/dynu/README.md index fc2a485..d904a32 100644 --- a/infrastructure/terraform/dynu/README.md +++ b/infrastructure/terraform/dynu/README.md @@ -73,6 +73,37 @@ These are generated outputs meant for operator review before use in production. ## Troubleshooting +### Plan shows a large wall of `+` values under outputs + +Cause: + +Terraform is planning to save **new output values** to state (for example, live records from `data.dynu_dns_records.root`). This is not creating DNS records by itself. + +How to verify: + +- Output-only changes appear under `Changes to Outputs`. +- Real DNS changes appear as `dynu_dns_record` resource create/update/delete actions. + +Use: + +```bash +terraform apply -refresh-only +``` + +to persist refreshed data source and output values only. + +### Error: `There is no function named "regexreplace"` + +Cause: + +`regexreplace` is not a Terraform function. Resource-name slugification should not be implemented in Terraform HCL for this workflow. + +Fix: + +- Keep `inventory.tf` focused on reading live records via `data.dynu_dns_records.root`. +- Keep Terraform outputs simple (for example, `/` mappings). +- Let `scripts/generate-brownfield-records.py` generate Terraform-safe resource names with Python `tf_name(record)`. + ### Error: `'"'"'dynu_dns_records'"'"'` Cause: diff --git a/infrastructure/terraform/dynu/inventory.tf b/infrastructure/terraform/dynu/inventory.tf index a13c08c..ff63537 100644 --- a/infrastructure/terraform/dynu/inventory.tf +++ b/infrastructure/terraform/dynu/inventory.tf @@ -1,16 +1,3 @@ data "dynu_dns_records" "root" { hostname = var.dynu_root_domain } - -locals { - dynu_dns_record_name_map = { - for record in data.dynu_dns_records.root.records : - format( - "%s_%s", - can(regex("^[a-z]", regexreplace(replace(lower(format("%s_%s", record.hostname, record.record_type)), "*", "wildcard"), "[^a-z0-9]+", "_"))) - ? trim(regexreplace(replace(lower(format("%s_%s", record.hostname, record.record_type)), "*", "wildcard"), "[^a-z0-9]+", "_"), "_") - : format("record_%s", trim(regexreplace(replace(lower(format("%s_%s", record.hostname, record.record_type)), "*", "wildcard"), "[^a-z0-9]+", "_"), "_")), - record.id - ) => record - } -} diff --git a/infrastructure/terraform/dynu/outputs.tf b/infrastructure/terraform/dynu/outputs.tf index 2190cbf..e209ee4 100644 --- a/infrastructure/terraform/dynu/outputs.tf +++ b/infrastructure/terraform/dynu/outputs.tf @@ -39,9 +39,9 @@ output "dynu_dns_hostnames" { } output "dynu_dns_record_import_ids" { - description = "Map of generated Terraform resource names to provider import IDs in domain_id/record_id format." + description = "Map of Dynu DNS record identity to provider import IDs in domain_id/record_id format." value = { - for name, record in local.dynu_dns_record_name_map : - name => format("%s/%s", record.domain_id, record.id) + for record in data.dynu_dns_records.root.records : + format("%s/%s/%s", record.hostname, record.record_type, record.id) => format("%s/%s", record.domain_id, record.id) } }