diff --git a/modules/gcp/dns-zone/README.md b/modules/gcp/dns-zone/README.md new file mode 100644 index 0000000..d0b393a --- /dev/null +++ b/modules/gcp/dns-zone/README.md @@ -0,0 +1,58 @@ +# DNS Module + +To create a zone in the sub project and then create the delegations in the parent project. + +# Quickstart + +```hcl +module "gcp-dns-zone" { + source = "github.com/streamnative/terraform-managed-cloud//modules/gcp/dns-zone" + + parent_project = "" + sub_project = "" + + parent_zone_name = "" + sub_zone_name = "" + sub_zone_dns_name = "" +} +``` + +## Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | >=1.2.0 | + +## Providers + +| Name | Version | +|------|---------| +| [google.parent](#provider\_google.parent) | n/a | +| [google.sub](#provider\_google.sub) | n/a | + +## Modules + +No modules. + +## Resources + +| Name | Type | +|------|------| +| [google_dns_managed_zone.sub](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/dns_managed_zone) | resource | +| [google_dns_record_set.delegate](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/dns_record_set) | resource | +| [google_dns_managed_zone.parent](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/dns_managed_zone) | data source | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [parent\_project](#input\_parent\_project) | The parent gcp project in which holds the paren zone | `string` | n/a | yes | +| [parent\_zone\_name](#input\_parent\_zone\_name) | The parent zone in which we create the delegation records | `string` | n/a | yes | +| [sub\_project](#input\_sub\_project) | The sub project in which holds the new zone | `string` | n/a | yes | +| [sub\_zone\_dns\_name](#input\_sub\_zone\_dns\_name) | The new dns name | `string` | n/a | yes | +| [sub\_zone\_name](#input\_sub\_zone\_name) | The new zone name | `string` | n/a | yes | + +## Outputs + +No outputs. + \ No newline at end of file diff --git a/modules/gcp/dns-zone/main.tf b/modules/gcp/dns-zone/main.tf new file mode 100644 index 0000000..7e2f7dd --- /dev/null +++ b/modules/gcp/dns-zone/main.tf @@ -0,0 +1,34 @@ +provider "google" { + alias = "parent" + + project = var.parent_project +} + +provider "google" { + alias = "sub" + + project = var.sub_project +} + +resource "google_dns_managed_zone" "sub" { + provider = google.sub + + name = var.sub_zone_name + dns_name = var.sub_zone_dns_name +} + +data "google_dns_managed_zone" "parent" { + provider = google.parent + + name = var.parent_zone_name +} + +resource "google_dns_record_set" "delegate" { + provider = google.parent + + managed_zone = data.google_dns_managed_zone.parent.name + name = google_dns_managed_zone.sub.dns_name + type = "NS" + ttl = "300" + rrdatas = google_dns_managed_zone.sub.name_servers +} diff --git a/modules/gcp/dns-zone/variables.tf b/modules/gcp/dns-zone/variables.tf new file mode 100644 index 0000000..b5333d6 --- /dev/null +++ b/modules/gcp/dns-zone/variables.tf @@ -0,0 +1,29 @@ +variable "parent_project" { + type = string + description = "The parent gcp project in which holds the paren zone" +} + +variable "sub_project" { + type = string + description = "The sub project in which holds the new zone" +} + +variable "parent_zone_name" { + type = string + description = "The parent zone in which we create the delegation records" +} + +variable "sub_zone_name" { + type = string + description = "The new zone name" +} + +variable "sub_zone_dns_name" { + type = string + description = "The new dns name" + + validation { + condition = endswith(var.sub_zone_dns_name, ".") + error_message = "DNS name must end with '.'" + } +} diff --git a/modules/gcp/dns-zone/versions.tf b/modules/gcp/dns-zone/versions.tf new file mode 100644 index 0000000..0074c18 --- /dev/null +++ b/modules/gcp/dns-zone/versions.tf @@ -0,0 +1,9 @@ +terraform { + required_version = ">=1.2.0" + + required_providers { + google = { + source = "hashicorp/google" + } + } +}