Fix Dynu inventory by removing unsupported regexreplace usage
This commit is contained in:
@@ -73,6 +73,37 @@ These are generated outputs meant for operator review before use in production.
|
|||||||
|
|
||||||
## Troubleshooting
|
## 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, `<domain_id>/<record_id>` mappings).
|
||||||
|
- Let `scripts/generate-brownfield-records.py` generate Terraform-safe resource names with Python `tf_name(record)`.
|
||||||
|
|
||||||
### Error: `'"'"'dynu_dns_records'"'"'`
|
### Error: `'"'"'dynu_dns_records'"'"'`
|
||||||
|
|
||||||
Cause:
|
Cause:
|
||||||
|
|||||||
@@ -1,16 +1,3 @@
|
|||||||
data "dynu_dns_records" "root" {
|
data "dynu_dns_records" "root" {
|
||||||
hostname = var.dynu_root_domain
|
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -39,9 +39,9 @@ output "dynu_dns_hostnames" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
output "dynu_dns_record_import_ids" {
|
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 = {
|
value = {
|
||||||
for name, record in local.dynu_dns_record_name_map :
|
for record in data.dynu_dns_records.root.records :
|
||||||
name => format("%s/%s", record.domain_id, record.id)
|
format("%s/%s/%s", record.hostname, record.record_type, record.id) => format("%s/%s", record.domain_id, record.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user