examples: remove random provider from live safe dns record

This commit is contained in:
beatz174-bit
2026-04-23 15:22:09 +10:00
parent 9835368941
commit afcaa2d90d
5 changed files with 22 additions and 21 deletions
+11 -8
View File
@@ -6,9 +6,9 @@ then you remove it with `terraform destroy`.
## Safety model ## 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: - Hostname format is:
- `<test_prefix>-<random_hex>.<dynu_root_domain>` - `<test_prefix>-<test_suffix>.<dynu_root_domain>`
- Creates exactly one record: - Creates exactly one record:
- `A` record, default content `198.51.100.10`, default TTL `300`. - `A` record, default content `198.51.100.10`, default TTL `300`.
- Does **not** import, update, replace, or delete existing production hostnames/records. - Does **not** import, update, replace, or delete existing production hostnames/records.
@@ -27,27 +27,30 @@ then you remove it with `terraform destroy`.
## Workflow ## Workflow
This example intentionally uses only the `dynu/dynu` provider (no `hashicorp/random`).
If you want per-run uniqueness, pass `test_suffix` explicitly.
```bash ```bash
go build -o terraform-provider-dynu go build -o terraform-provider-dynu
cd examples/live_safe_dns_record cd examples/live_safe_dns_record
cp terraform.tfvars.example terraform.tfvars 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 validate
terraform plan terraform plan -var="test_suffix=$(date +%s)"
terraform apply 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: then clean up:
```bash ```bash
terraform destroy terraform destroy -var="test_suffix=$(date +%s)"
``` ```
## Cleanup guidance ## Cleanup guidance
- Always run `terraform destroy` after testing. - Always run `terraform destroy` after testing.
- If apply is interrupted or partially succeeds, rerun `terraform destroy` from this same - 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 - If re-running without destroying first, Terraform may keep state for the previous
disposable record until it is destroyed. disposable record until it is destroyed.
+1 -10
View File
@@ -3,11 +3,6 @@ terraform {
dynu = { dynu = {
source = "dynu/dynu" source = "dynu/dynu"
} }
random = {
source = "hashicorp/random"
version = ">= 3.6.0"
}
} }
} }
@@ -15,12 +10,8 @@ provider "dynu" {
api_key = var.dynu_api_key api_key = var.dynu_api_key
} }
resource "random_id" "suffix" {
byte_length = 4
}
locals { 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}" disposable_hostname = "${local.disposable_label}.${var.dynu_root_domain}"
} }
+1 -1
View File
@@ -1,5 +1,5 @@
output "disposable_hostname" { output "disposable_hostname" {
description = "Generated unique disposable hostname created by this run." description = "Disposable hostname created by this run."
value = local.disposable_hostname value = local.disposable_hostname
} }
@@ -2,9 +2,10 @@
# Do NOT put an existing full production hostname here. # Do NOT put an existing full production hostname here.
dynu_root_domain = "example.com" dynu_root_domain = "example.com"
# Optional prefix for generated disposable hostname labels. # Optional naming for disposable hostname labels.
# Final hostname format: <test_prefix>-<random_hex>.<dynu_root_domain> # Final hostname format: <test_prefix>-<test_suffix>.<dynu_root_domain>
test_prefix = "tfacc" test_prefix = "tfacc"
test_suffix = "manual"
# Optional: documentation/test IP for disposable A record content. # Optional: documentation/test IP for disposable A record content.
test_ip = "198.51.100.10" test_ip = "198.51.100.10"
@@ -16,6 +16,12 @@ variable "test_prefix" {
default = "tfacc" default = "tfacc"
} }
variable "test_suffix" {
description = "Suffix for disposable hostname uniqueness (set explicitly per run if needed)."
type = string
default = "manual"
}
variable "test_ip" { variable "test_ip" {
description = "Safe documentation/test IPv4 value for the disposable A record." description = "Safe documentation/test IPv4 value for the disposable A record."
type = string type = string