From 2980f1c602c865f07aa26055cbef7d49c99524ee Mon Sep 17 00:00:00 2001 From: Johnny Che <114401755+chej-hod@users.noreply.github.com> Date: Tue, 8 Oct 2024 12:00:50 +0100 Subject: [PATCH] CCL-663: initial tf module for deploying R53 Zones with Records (#184) * CCL-663: initial tf module for deploying R53 Zones with Records * CCL-663: initial tf module for deploying R53 Zones with Records * CCL-663: initial tf module for deploying R53 Zones with Records --- .../route53_zone_with_records/README.md | 87 +++++++++++++++++++ .../route53_zone_with_records/main.tf | 21 +++++ .../route53_zone_with_records/outputs.tf | 11 +++ .../route53_zone_with_records/variables.tf | 21 +++++ .../route53_zone_with_records/versions.tf | 9 ++ 5 files changed, 149 insertions(+) create mode 100644 modules/aws/networking/route53_zone_with_records/README.md create mode 100644 modules/aws/networking/route53_zone_with_records/main.tf create mode 100644 modules/aws/networking/route53_zone_with_records/outputs.tf create mode 100644 modules/aws/networking/route53_zone_with_records/variables.tf create mode 100644 modules/aws/networking/route53_zone_with_records/versions.tf diff --git a/modules/aws/networking/route53_zone_with_records/README.md b/modules/aws/networking/route53_zone_with_records/README.md new file mode 100644 index 0000000..3548c7a --- /dev/null +++ b/modules/aws/networking/route53_zone_with_records/README.md @@ -0,0 +1,87 @@ +# core-cloud-vpc-endpoint-tf-module - VPC Endpoint Terraform Module + +## Example Usage +``` +module "r53_zone_with_rec" { + source = "git::git::https://github.com/UKHomeOffice/core-cloud-terraform-modules.git//modules/aws/networking/route53_zone_with_records?ref=main" + + vpc_id = ["vpc-xxxxxxxxxxxxxxxxx"] + r53_zone = "example.com" + r53_records_as_json = jsonencode( + [ + { + name = "api" + type = "A" + alias = { + name = "xxxxxxxxxxx.execute-api.eu-west-1.amazonaws.com" + zone_id = "XXXXXXXXXX" + } + }, + { + name = "www" + type = "A" + ttl = 3600 + records = [ + "127.0.0.1", + ] + }, + ] + ) +} + + module "vpce" { + source = "git::git::https://github.com/UKHomeOffice/core-cloud-vpc-endpoint-tf-module.git?ref=main" + + vpc_endpoint_name = "some_service" + vpc_id = "vpc-xxxxxxxxxxxxxxxxx" + service_name = "com.amazonaws.vpce..xxxxxxxxxxxxxxx" + security_group_ids = ["sg-xxxxxxxxxxxxxx"] + subnet_ids = ["subnet-axxxxxxxxx", "subnet-bxxxxxxxxx", "subnet-cxxxxxxxx"] + managed_private_dns_enabled = false + custom_private_r53_zone = "private.example.com" + } +``` + + +## Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | >= 1.0 | +| [aws](#requirement\_aws) | ~> 5.0 | + +## Providers + +| Name | Version | +|------|---------| +| [aws](#provider\_aws) | ~> 5.0 | + +## Modules + +| Name | Source | Version | +|------|--------|---------| +| [records](#module\_records) | terraform-aws-modules/route53/aws//modules/records | ~> 4.0 | + +## Resources + +| Name | Type | +|------|------| +| [aws_route53_zone.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_zone) | resource | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [r53\_records\_as\_json](#input\_r53\_records\_as\_json) | A JSON encoded String of the records for the Route53 Zone you wish to create, please see example for usage. It's JSON encoded due to Terragrunt Bug - https://github.com/gruntwork-io/terragrunt/issues/1211 | `string` | n/a | yes | +| [r53\_zone](#input\_r53\_zone) | The name of the Route53 Zone. e.g example.com | `string` | n/a | yes | +| [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no | +| [vpc\_id](#input\_vpc\_id) | A list of VPCs to associate the Route53 Zone with - setting this will create a Private Hosted Zone (PHZ) | `list(string)` | `[]` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| [aws\_route53\_record\_fqdn](#output\_aws\_route53\_record\_fqdn) | n/a | +| [aws\_route53\_record\_name](#output\_aws\_route53\_record\_name) | n/a | +| [aws\_route53\_record\_zone\_id](#output\_aws\_route53\_record\_zone\_id) | n/a | + diff --git a/modules/aws/networking/route53_zone_with_records/main.tf b/modules/aws/networking/route53_zone_with_records/main.tf new file mode 100644 index 0000000..d5ceaef --- /dev/null +++ b/modules/aws/networking/route53_zone_with_records/main.tf @@ -0,0 +1,21 @@ +resource "aws_route53_zone" "this" { + name = var.r53_zone + + dynamic "vpc" { + for_each = toset(var.vpc_id) + content { + vpc_id = vpc.key + } + } + tags = var.tags +} + +module "records" { + source = "terraform-aws-modules/route53/aws//modules/records" + version = "~> 4.0" + + zone_id = aws_route53_zone.this.zone_id + records_jsonencoded = var.r53_records_as_json + + depends_on = [aws_route53_zone.this] +} diff --git a/modules/aws/networking/route53_zone_with_records/outputs.tf b/modules/aws/networking/route53_zone_with_records/outputs.tf new file mode 100644 index 0000000..6a68370 --- /dev/null +++ b/modules/aws/networking/route53_zone_with_records/outputs.tf @@ -0,0 +1,11 @@ +output "aws_route53_record_zone_id" { + value = aws_route53_zone.this.zone_id +} + +output "aws_route53_record_name" { + value = module.records.route53_record_name +} + +output "aws_route53_record_fqdn" { + value = module.records.route53_record_fqdn +} diff --git a/modules/aws/networking/route53_zone_with_records/variables.tf b/modules/aws/networking/route53_zone_with_records/variables.tf new file mode 100644 index 0000000..b5f1f1a --- /dev/null +++ b/modules/aws/networking/route53_zone_with_records/variables.tf @@ -0,0 +1,21 @@ +variable "vpc_id" { + description = "A list of VPCs to associate the Route53 Zone with - setting this will create a Private Hosted Zone (PHZ)" + type = list(string) + default = [] +} + +variable "r53_zone" { + description = "The name of the Route53 Zone. e.g example.com" + type = string +} + +variable "r53_records_as_json" { + description = "A JSON encoded String of the records for the Route53 Zone you wish to create, please see example for usage. It's JSON encoded due to Terragrunt Bug - https://github.com/gruntwork-io/terragrunt/issues/1211" + type = string +} + +variable "tags" { + description = "A map of tags to add to all resources" + type = map(string) + default = {} +} diff --git a/modules/aws/networking/route53_zone_with_records/versions.tf b/modules/aws/networking/route53_zone_with_records/versions.tf new file mode 100644 index 0000000..802f8c4 --- /dev/null +++ b/modules/aws/networking/route53_zone_with_records/versions.tf @@ -0,0 +1,9 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 5.0" + } + } + required_version = ">= 1.0" +}