Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(DMVP-5080): have ability to output dns zone delegation NS records #7

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Allows to create aws route53 zone and record with simple manner,
supports alb/loadbalancer and cdn/cloudfront cases

# for enabling git pre-commit/commit-msg hooks run this(other repos will also have it set as it set globally)
```sh
git config --global core.hooksPath ./githooks
```

# simple example with alb
```hcl
module "dns" {
Expand Down Expand Up @@ -55,5 +60,6 @@ No resources.

| Name | Description |
|------|-------------|
| <a name="output_ns_delegation_set"></a> [ns\_delegation\_set](#output\_ns\_delegation\_set) | The NS records list for zone to use as delegation set |
| <a name="output_zone_id"></a> [zone\_id](#output\_zone\_id) | zone id |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
3 changes: 2 additions & 1 deletion modules/route53/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ No requirements.

| Name | Source | Version |
|------|--------|---------|
| <a name="module_zone"></a> [zone](#module\_zone) | ./zone | n/a |
| <a name="module_zone"></a> [zone](#module\_zone) | ../zone | n/a |

## Resources

Expand All @@ -123,5 +123,6 @@ No requirements.
| Name | Description |
|------|-------------|
| <a name="output_arn"></a> [arn](#output\_arn) | Returns zone arn. |
| <a name="output_name_servers"></a> [name\_servers](#output\_name\_servers) | Returns zone name servers list. |
| <a name="output_zone_id"></a> [zone\_id](#output\_zone\_id) | Returns zone id. |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
2 changes: 1 addition & 1 deletion modules/route53/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module "zone" {
source = "./zone"
source = "../zone"
count = var.create_zone ? 1 : 0

name = var.zone
Expand Down
5 changes: 5 additions & 0 deletions modules/route53/output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ output "arn" {
value = var.create_zone ? module.zone[0].arn : data.aws_route53_zone.main[0].arn
description = "Returns zone arn."
}

output "name_servers" {
value = var.create_zone ? module.zone[0].name_servers : data.aws_route53_zone.main[0].name_servers
description = "Returns zone name servers list."
}
1 change: 1 addition & 0 deletions modules/route53/zone/README.md → modules/zone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ No modules.
| Name | Description |
|------|-------------|
| <a name="output_arn"></a> [arn](#output\_arn) | Return created zone arn. |
| <a name="output_name_servers"></a> [name\_servers](#output\_name\_servers) | Return created zone name\_servers. |
| <a name="output_zone_id"></a> [zone\_id](#output\_zone\_id) | Return created zone id. |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
3 changes: 3 additions & 0 deletions modules/zone/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resource "aws_route53_zone" "main" {
name = var.name
}
14 changes: 4 additions & 10 deletions modules/route53/zone/main.tf → modules/zone/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
# variables
variable "name" {
type = string
description = "Route53 Zone name"
}

# outputs
output "zone_id" {
value = aws_route53_zone.main.zone_id
description = "Return created zone id."
}

output "arn" {
value = aws_route53_zone.main.arn
description = "Return created zone arn."
}

# resources
resource "aws_route53_zone" "main" {
name = var.name
output "name_servers" {
value = aws_route53_zone.main.name_servers
description = "Return created zone name_servers."
}
5 changes: 5 additions & 0 deletions modules/zone/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# variables
variable "name" {
type = string
description = "Route53 Zone name"
}
5 changes: 5 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ output "zone_id" {
value = module.zone_and_records.zone_id
description = "zone id"
}

output "ns_delegation_set" {
value = [for item in module.zone_and_records.name_servers : "${item}."]
description = "The NS records list for zone to use as delegation set"
}
4 changes: 0 additions & 4 deletions tests/alb_record/0-setup.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
terraform {
required_providers {
test = {
source = "terraform.io/builtin/test"
}

aws = {
source = "hashicorp/aws"
version = ">= 3.41"
Expand Down
9 changes: 0 additions & 9 deletions tests/alb_record/2-assert.tf

This file was deleted.

2 changes: 0 additions & 2 deletions tests/alb_record/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.41 |
| <a name="provider_test"></a> [test](#provider\_test) | n/a |

## Modules

Expand All @@ -28,7 +27,6 @@
| [aws_default_subnet.default_az_a](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/default_subnet) | resource |
| [aws_default_subnet.default_az_b](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/default_subnet) | resource |
| [aws_lb.test](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb) | resource |
| test_assertions.dummy | resource |

## Inputs

Expand Down
9 changes: 0 additions & 9 deletions tests/alb_record_private/2-assert.tf

This file was deleted.

4 changes: 0 additions & 4 deletions tests/basic/0-setup.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
terraform {
required_providers {
test = {
source = "terraform.io/builtin/test"
}

aws = {
source = "hashicorp/aws"
version = ">= 3.41"
Expand Down
9 changes: 0 additions & 9 deletions tests/basic/2-assert.tf

This file was deleted.

8 changes: 2 additions & 6 deletions tests/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

## Providers

| Name | Version |
|------|---------|
| <a name="provider_test"></a> [test](#provider\_test) | n/a |
No providers.

## Modules

Expand All @@ -22,9 +20,7 @@

## Resources

| Name | Type |
|------|------|
| test_assertions.dummy | resource |
No resources.

## Inputs

Expand Down
20 changes: 20 additions & 0 deletions tests/create-zone/0-setup.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.41"
}
}

required_version = ">= 1.3.0"
}

/**
* set the following env vars so that aws provider will get authenticated before apply:

export AWS_ACCESS_KEY_ID=xxxxxxxxxxxxxxxxxxxxxxxx
export AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxx
*/
provider "aws" {
region = "eu-central-1"
}
6 changes: 6 additions & 0 deletions tests/create-zone/1-example.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module "this" {
source = "../../"

zone = "test-zone-creation.dasmeta.com"
create_zone = true
}
32 changes: 32 additions & 0 deletions tests/create-zone/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# basic

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.41 |

## Providers

No providers.

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_this"></a> [this](#module\_this) | ../../ | n/a |

## Resources

No resources.

## Inputs

No inputs.

## Outputs

No outputs.
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Loading