From afcaa2d90d033e2fa5c377c8a5ce7b1c259a5cdb Mon Sep 17 00:00:00 2001 From: beatz174-bit Date: Thu, 23 Apr 2026 15:22:09 +1000 Subject: [PATCH] examples: remove random provider from live safe dns record --- examples/live_safe_dns_record/README.md | 19 +++++++++++-------- examples/live_safe_dns_record/main.tf | 11 +---------- examples/live_safe_dns_record/outputs.tf | 2 +- .../terraform.tfvars.example | 5 +++-- examples/live_safe_dns_record/variables.tf | 6 ++++++ 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/examples/live_safe_dns_record/README.md b/examples/live_safe_dns_record/README.md index 260ec7e..f94faf5 100644 --- a/examples/live_safe_dns_record/README.md +++ b/examples/live_safe_dns_record/README.md @@ -6,9 +6,9 @@ then you remove it with `terraform destroy`. ## Safety model -- Creates a **new unique subdomain** every run using `random_id`. +- Creates a **new disposable subdomain** using configurable `test_prefix` and `test_suffix` values. - Hostname format is: - - `-.` + - `-.` - Creates exactly one record: - `A` record, default content `198.51.100.10`, default TTL `300`. - Does **not** import, update, replace, or delete existing production hostnames/records. @@ -27,27 +27,30 @@ then you remove it with `terraform destroy`. ## Workflow +This example intentionally uses only the `dynu/dynu` provider (no `hashicorp/random`). +If you want per-run uniqueness, pass `test_suffix` explicitly. + ```bash go build -o terraform-provider-dynu cd examples/live_safe_dns_record cp terraform.tfvars.example terraform.tfvars -# edit terraform.tfvars and set only dynu_root_domain +# edit terraform.tfvars and set dynu_root_domain (and optionally test_suffix) terraform validate -terraform plan -terraform apply +terraform plan -var="test_suffix=$(date +%s)" +terraform apply -var="test_suffix=$(date +%s)" ``` -After apply, inspect outputs to confirm the generated disposable hostname and record ID, +After apply, inspect outputs to confirm the disposable hostname and record ID, then clean up: ```bash -terraform destroy +terraform destroy -var="test_suffix=$(date +%s)" ``` ## Cleanup guidance - Always run `terraform destroy` after testing. - If apply is interrupted or partially succeeds, rerun `terraform destroy` from this same - directory with the same `terraform.tfvars` and state files. + directory with the same `terraform.tfvars`, CLI vars, and state files. - If re-running without destroying first, Terraform may keep state for the previous disposable record until it is destroyed. diff --git a/examples/live_safe_dns_record/main.tf b/examples/live_safe_dns_record/main.tf index 38691d0..b898765 100644 --- a/examples/live_safe_dns_record/main.tf +++ b/examples/live_safe_dns_record/main.tf @@ -3,11 +3,6 @@ terraform { dynu = { source = "dynu/dynu" } - - random = { - source = "hashicorp/random" - version = ">= 3.6.0" - } } } @@ -15,12 +10,8 @@ provider "dynu" { api_key = var.dynu_api_key } -resource "random_id" "suffix" { - byte_length = 4 -} - locals { - disposable_label = "${var.test_prefix}-${lower(random_id.suffix.hex)}" + disposable_label = "${var.test_prefix}-${var.test_suffix}" disposable_hostname = "${local.disposable_label}.${var.dynu_root_domain}" } diff --git a/examples/live_safe_dns_record/outputs.tf b/examples/live_safe_dns_record/outputs.tf index 65b7406..c5a6ac4 100644 --- a/examples/live_safe_dns_record/outputs.tf +++ b/examples/live_safe_dns_record/outputs.tf @@ -1,5 +1,5 @@ output "disposable_hostname" { - description = "Generated unique disposable hostname created by this run." + description = "Disposable hostname created by this run." value = local.disposable_hostname } diff --git a/examples/live_safe_dns_record/terraform.tfvars.example b/examples/live_safe_dns_record/terraform.tfvars.example index e2599cc..b378b58 100644 --- a/examples/live_safe_dns_record/terraform.tfvars.example +++ b/examples/live_safe_dns_record/terraform.tfvars.example @@ -2,9 +2,10 @@ # Do NOT put an existing full production hostname here. dynu_root_domain = "example.com" -# Optional prefix for generated disposable hostname labels. -# Final hostname format: -. +# Optional naming for disposable hostname labels. +# Final hostname format: -. test_prefix = "tfacc" +test_suffix = "manual" # Optional: documentation/test IP for disposable A record content. test_ip = "198.51.100.10" diff --git a/examples/live_safe_dns_record/variables.tf b/examples/live_safe_dns_record/variables.tf index 1e65559..94c81fa 100644 --- a/examples/live_safe_dns_record/variables.tf +++ b/examples/live_safe_dns_record/variables.tf @@ -16,6 +16,12 @@ variable "test_prefix" { default = "tfacc" } +variable "test_suffix" { + description = "Suffix for disposable hostname uniqueness (set explicitly per run if needed)." + type = string + default = "manual" +} + variable "test_ip" { description = "Safe documentation/test IPv4 value for the disposable A record." type = string