Skip to content

Commit

Permalink
feat: add gcp dns-zone module
Browse files Browse the repository at this point in the history
Signed-off-by: Max Xu <[email protected]>
  • Loading branch information
maxsxu committed Oct 27, 2023
1 parent 0356a47 commit fc4a2f1
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 0 deletions.
58 changes: 58 additions & 0 deletions modules/gcp/dns-zone/README.md
Original file line number Diff line number Diff line change
@@ -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 = "<input-here>"
sub_project = "<input-here>"
parent_zone_name = "<input-here>"
sub_zone_name = "<input-here>"
sub_zone_dns_name = "<input-here>"
}
```
<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >=1.2.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_google.parent"></a> [google.parent](#provider\_google.parent) | n/a |
| <a name="provider_google.sub"></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 |
|------|-------------|------|---------|:--------:|
| <a name="input_parent_project"></a> [parent\_project](#input\_parent\_project) | The parent gcp project in which holds the paren zone | `string` | n/a | yes |
| <a name="input_parent_zone_name"></a> [parent\_zone\_name](#input\_parent\_zone\_name) | The parent zone in which we create the delegation records | `string` | n/a | yes |
| <a name="input_sub_project"></a> [sub\_project](#input\_sub\_project) | The sub project in which holds the new zone | `string` | n/a | yes |
| <a name="input_sub_zone_dns_name"></a> [sub\_zone\_dns\_name](#input\_sub\_zone\_dns\_name) | The new dns name | `string` | n/a | yes |
| <a name="input_sub_zone_name"></a> [sub\_zone\_name](#input\_sub\_zone\_name) | The new zone name | `string` | n/a | yes |

## Outputs

No outputs.
<!-- END_TF_DOCS -->
34 changes: 34 additions & 0 deletions modules/gcp/dns-zone/main.tf
Original file line number Diff line number Diff line change
@@ -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
}
29 changes: 29 additions & 0 deletions modules/gcp/dns-zone/variables.tf
Original file line number Diff line number Diff line change
@@ -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 '.'"
}
}
9 changes: 9 additions & 0 deletions modules/gcp/dns-zone/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_version = ">=1.2.0"

required_providers {
google = {
source = "hashicorp/google"
}
}
}

0 comments on commit fc4a2f1

Please sign in to comment.