From fd4cf34f0b6571dbf9c8d2bfa4dce306c47c6c11 Mon Sep 17 00:00:00 2001 From: Tigran Muradyan Date: Wed, 21 Aug 2024 20:08:08 +0400 Subject: [PATCH] fix(DMVP-5080): have ability to output dns zone delegation NS records --- README.md | 6 ++++ modules/route53/README.md | 3 +- modules/route53/main.tf | 2 +- modules/route53/output.tf | 5 +++ modules/{route53 => }/zone/README.md | 1 + modules/zone/main.tf | 3 ++ .../{route53/zone/main.tf => zone/outputs.tf} | 14 +++----- modules/zone/variables.tf | 5 +++ outputs.tf | 5 +++ tests/alb_record/0-setup.tf | 4 --- tests/alb_record/2-assert.tf | 9 ------ tests/alb_record/README.md | 2 -- tests/alb_record_private/2-assert.tf | 9 ------ tests/basic/0-setup.tf | 4 --- tests/basic/2-assert.tf | 9 ------ tests/basic/README.md | 8 ++--- tests/create-zone/0-setup.tf | 20 ++++++++++++ tests/create-zone/1-example.tf | 6 ++++ tests/create-zone/README.md | 32 +++++++++++++++++++ 19 files changed, 92 insertions(+), 55 deletions(-) rename modules/{route53 => }/zone/README.md (88%) create mode 100644 modules/zone/main.tf rename modules/{route53/zone/main.tf => zone/outputs.tf} (56%) create mode 100644 modules/zone/variables.tf delete mode 100644 tests/alb_record/2-assert.tf delete mode 100644 tests/alb_record_private/2-assert.tf delete mode 100644 tests/basic/2-assert.tf create mode 100644 tests/create-zone/0-setup.tf create mode 100644 tests/create-zone/1-example.tf create mode 100644 tests/create-zone/README.md diff --git a/README.md b/README.md index 2cf3893..78f5f28 100644 --- a/README.md +++ b/README.md @@ -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" { @@ -55,5 +60,6 @@ No resources. | Name | Description | |------|-------------| +| [ns\_delegation\_set](#output\_ns\_delegation\_set) | The NS records list for zone to use as delegation set | | [zone\_id](#output\_zone\_id) | zone id | diff --git a/modules/route53/README.md b/modules/route53/README.md index 17d7481..40f312f 100644 --- a/modules/route53/README.md +++ b/modules/route53/README.md @@ -99,7 +99,7 @@ No requirements. | Name | Source | Version | |------|--------|---------| -| [zone](#module\_zone) | ./zone | n/a | +| [zone](#module\_zone) | ../zone | n/a | ## Resources @@ -123,5 +123,6 @@ No requirements. | Name | Description | |------|-------------| | [arn](#output\_arn) | Returns zone arn. | +| [name\_servers](#output\_name\_servers) | Returns zone name servers list. | | [zone\_id](#output\_zone\_id) | Returns zone id. | diff --git a/modules/route53/main.tf b/modules/route53/main.tf index a776499..91efd72 100644 --- a/modules/route53/main.tf +++ b/modules/route53/main.tf @@ -1,5 +1,5 @@ module "zone" { - source = "./zone" + source = "../zone" count = var.create_zone ? 1 : 0 name = var.zone diff --git a/modules/route53/output.tf b/modules/route53/output.tf index 4d7372c..76551bf 100644 --- a/modules/route53/output.tf +++ b/modules/route53/output.tf @@ -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." +} diff --git a/modules/route53/zone/README.md b/modules/zone/README.md similarity index 88% rename from modules/route53/zone/README.md rename to modules/zone/README.md index f578991..ea2897d 100644 --- a/modules/route53/zone/README.md +++ b/modules/zone/README.md @@ -32,5 +32,6 @@ No modules. | Name | Description | |------|-------------| | [arn](#output\_arn) | Return created zone arn. | +| [name\_servers](#output\_name\_servers) | Return created zone name\_servers. | | [zone\_id](#output\_zone\_id) | Return created zone id. | diff --git a/modules/zone/main.tf b/modules/zone/main.tf new file mode 100644 index 0000000..7eb2e2f --- /dev/null +++ b/modules/zone/main.tf @@ -0,0 +1,3 @@ +resource "aws_route53_zone" "main" { + name = var.name +} diff --git a/modules/route53/zone/main.tf b/modules/zone/outputs.tf similarity index 56% rename from modules/route53/zone/main.tf rename to modules/zone/outputs.tf index 050dd5a..61367b7 100644 --- a/modules/route53/zone/main.tf +++ b/modules/zone/outputs.tf @@ -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." } diff --git a/modules/zone/variables.tf b/modules/zone/variables.tf new file mode 100644 index 0000000..64c3e26 --- /dev/null +++ b/modules/zone/variables.tf @@ -0,0 +1,5 @@ +# variables +variable "name" { + type = string + description = "Route53 Zone name" +} diff --git a/outputs.tf b/outputs.tf index c66c3b2..2b1623a 100644 --- a/outputs.tf +++ b/outputs.tf @@ -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" +} diff --git a/tests/alb_record/0-setup.tf b/tests/alb_record/0-setup.tf index 698b24c..d576ec6 100644 --- a/tests/alb_record/0-setup.tf +++ b/tests/alb_record/0-setup.tf @@ -1,9 +1,5 @@ terraform { required_providers { - test = { - source = "terraform.io/builtin/test" - } - aws = { source = "hashicorp/aws" version = ">= 3.41" diff --git a/tests/alb_record/2-assert.tf b/tests/alb_record/2-assert.tf deleted file mode 100644 index 99458ca..0000000 --- a/tests/alb_record/2-assert.tf +++ /dev/null @@ -1,9 +0,0 @@ -resource "test_assertions" "dummy" { - component = "this" - - equal "scheme" { - description = "As module does not have any output and data just make sure the case runs. Probably can be thrown away." - got = "all good" - want = "all good" - } -} diff --git a/tests/alb_record/README.md b/tests/alb_record/README.md index 85e5f0a..89d6061 100644 --- a/tests/alb_record/README.md +++ b/tests/alb_record/README.md @@ -13,7 +13,6 @@ | Name | Version | |------|---------| | [aws](#provider\_aws) | >= 3.41 | -| [test](#provider\_test) | n/a | ## Modules @@ -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 diff --git a/tests/alb_record_private/2-assert.tf b/tests/alb_record_private/2-assert.tf deleted file mode 100644 index 4ffba4b..0000000 --- a/tests/alb_record_private/2-assert.tf +++ /dev/null @@ -1,9 +0,0 @@ -# resource "test_assertions" "dummy" { -# component = "this" - -# equal "scheme" { -# description = "As module does not have any output and data just make sure the case runs. Probably can be thrown away." -# got = "all good" -# want = "all good" -# } -# } diff --git a/tests/basic/0-setup.tf b/tests/basic/0-setup.tf index 9c76587..a859a5e 100644 --- a/tests/basic/0-setup.tf +++ b/tests/basic/0-setup.tf @@ -1,9 +1,5 @@ terraform { required_providers { - test = { - source = "terraform.io/builtin/test" - } - aws = { source = "hashicorp/aws" version = ">= 3.41" diff --git a/tests/basic/2-assert.tf b/tests/basic/2-assert.tf deleted file mode 100644 index 99458ca..0000000 --- a/tests/basic/2-assert.tf +++ /dev/null @@ -1,9 +0,0 @@ -resource "test_assertions" "dummy" { - component = "this" - - equal "scheme" { - description = "As module does not have any output and data just make sure the case runs. Probably can be thrown away." - got = "all good" - want = "all good" - } -} diff --git a/tests/basic/README.md b/tests/basic/README.md index 08dd597..221cf64 100644 --- a/tests/basic/README.md +++ b/tests/basic/README.md @@ -10,9 +10,7 @@ ## Providers -| Name | Version | -|------|---------| -| [test](#provider\_test) | n/a | +No providers. ## Modules @@ -22,9 +20,7 @@ ## Resources -| Name | Type | -|------|------| -| test_assertions.dummy | resource | +No resources. ## Inputs diff --git a/tests/create-zone/0-setup.tf b/tests/create-zone/0-setup.tf new file mode 100644 index 0000000..a859a5e --- /dev/null +++ b/tests/create-zone/0-setup.tf @@ -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" +} diff --git a/tests/create-zone/1-example.tf b/tests/create-zone/1-example.tf new file mode 100644 index 0000000..65b8a4d --- /dev/null +++ b/tests/create-zone/1-example.tf @@ -0,0 +1,6 @@ +module "this" { + source = "../../" + + zone = "test-zone-creation.dasmeta.com" + create_zone = true +} diff --git a/tests/create-zone/README.md b/tests/create-zone/README.md new file mode 100644 index 0000000..221cf64 --- /dev/null +++ b/tests/create-zone/README.md @@ -0,0 +1,32 @@ +# basic + + +## Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | >= 1.3.0 | +| [aws](#requirement\_aws) | >= 3.41 | + +## Providers + +No providers. + +## Modules + +| Name | Source | Version | +|------|--------|---------| +| [this](#module\_this) | ../../ | n/a | + +## Resources + +No resources. + +## Inputs + +No inputs. + +## Outputs + +No outputs. +