terraform-google-modules / terraform-google-cloud-dns

Creates and manages Cloud DNS public or private zones and their records
https://registry.terraform.io/modules/terraform-google-modules/cloud-dns/google
Apache License 2.0
57 stars 80 forks source link

Auto-replace dots with dashes in name, or possible auto-generate it from domain #79

Closed jeheyer closed 8 months ago

jeheyer commented 10 months ago

TL;DR

A common mistake I make is confusing name with domain, and the subsequent name constraints around them:

name = name of the managed zone, must be lowercases chars and dashes domain = DNS domain name, must end in .

Having some validations around these to detect them at the plan state would be great, or, better, yet, being able to essentially auto-correct these via string manipulation.

Terraform Resources

google_dns_managed_zone

Detailed design

variable "name" {
  description = "Zone name, must be unique within the project."
  type        = string
  default     = null
}

# Auto-generate name based on domain:
name      = lower(coalesce(var.name, trimsuffix(replace(var.domain, ".", "-"), "-")))

# Add a '.' to domain if required:
dns_name       = endswith(var.domain, ".") ? var.domain : "${var.domain}."

Additional information

https://github.com/aws2gcp/gcp-network-terraform/blob/main/dns/dns_zones.tf

github-actions[bot] commented 8 months ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days