Merge pull request #21 from beatz174-bit/codex/update-terraform-example-to-remove-random-provider

examples: remove random provider dependency from live_safe_dns_record
This commit is contained in:
beatz174-bit
2026-04-23 15:32:54 +10:00
committed by GitHub
5 changed files with 24 additions and 22 deletions
+13 -9
View File
@@ -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:
- `<test_prefix>-<random_hex>.<dynu_root_domain>`
- `<test_prefix>-<test_suffix>.<dynu_root_domain>`
- 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,31 @@ 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
TEST_SUFFIX="$(date +%s)"
terraform plan -var="test_suffix=${TEST_SUFFIX}"
terraform apply -var="test_suffix=${TEST_SUFFIX}"
```
After apply, inspect outputs to confirm the generated disposable hostname and record ID,
then clean up:
After apply, inspect outputs to confirm the disposable hostname and record ID,
then clean up using the **same** suffix value:
```bash
terraform destroy
terraform destroy -var="test_suffix=${TEST_SUFFIX}"
```
## 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.
+1 -10
View File
@@ -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}"
}
+1 -1
View File
@@ -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
}
@@ -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: <test_prefix>-<random_hex>.<dynu_root_domain>
# Optional naming for disposable hostname labels.
# Final hostname format: <test_prefix>-<test_suffix>.<dynu_root_domain>
test_prefix = "tfacc"
test_suffix = "manual"
# Optional: documentation/test IP for disposable A record content.
test_ip = "198.51.100.10"
@@ -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