Skip to content

Commit 67b5cf3

Browse files
renebarbosaflRene Barbosaantonbabenko
authored
feat: Add resolver-endpoints submodule (#106)
Co-authored-by: Rene Barbosa <[email protected]> Co-authored-by: Anton Babenko <[email protected]>
1 parent 69d17ca commit 67b5cf3

File tree

8 files changed

+279
-1
lines changed

8 files changed

+279
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ There are independent submodules:
99
- [zones](https://github.com/terraform-aws-modules/terraform-aws-route53/tree/master/modules/zones) - to manage Route53 zones
1010
- [records](https://github.com/terraform-aws-modules/terraform-aws-route53/tree/master/modules/records) - to manage Route53 records
1111
- [delegation-sets](https://github.com/terraform-aws-modules/terraform-aws-route53/tree/master/modules/delegation-sets) - to manage Route53 delegation sets
12+
- [resolver-endpoints](https://github.com/terraform-aws-modules/terraform-aws-route53/tree/master/modules/resolver-endpoints) - to manage Route53 resolver endpoints
1213
- [resolver-rule-associations](https://github.com/terraform-aws-modules/terraform-aws-route53/tree/master/modules/resolver-rule-associations) - to manage Route53 resolver rule associations
1314

1415
## Usage

examples/complete/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ Note that this example may create resources which cost money. Run `terraform des
3737
| <a name="module_cloudfront"></a> [cloudfront](#module\_cloudfront) | terraform-aws-modules/cloudfront/aws | ~> 3.0 |
3838
| <a name="module_delegation_sets"></a> [delegation\_sets](#module\_delegation\_sets) | ../../modules/delegation-sets | n/a |
3939
| <a name="module_disabled_records"></a> [disabled\_records](#module\_disabled\_records) | ../../modules/records | n/a |
40+
| <a name="module_disabled_resolver_endpoints"></a> [disabled\_resolver\_endpoints](#module\_disabled\_resolver\_endpoints) | ../../modules/resolver-endpoints | n/a |
4041
| <a name="module_records"></a> [records](#module\_records) | ../../modules/records | n/a |
4142
| <a name="module_records_with_full_names"></a> [records\_with\_full\_names](#module\_records\_with\_full\_names) | ../../modules/records | n/a |
43+
| <a name="module_resolver_endpoints"></a> [resolver\_endpoints](#module\_resolver\_endpoints) | ../../modules/resolver-endpoints | n/a |
4244
| <a name="module_resolver_rule_associations"></a> [resolver\_rule\_associations](#module\_resolver\_rule\_associations) | ../../modules/resolver-rule-associations | n/a |
4345
| <a name="module_s3_bucket"></a> [s3\_bucket](#module\_s3\_bucket) | terraform-aws-modules/s3-bucket/aws | n/a |
4446
| <a name="module_terragrunt"></a> [terragrunt](#module\_terragrunt) | ../../modules/records | n/a |
@@ -52,6 +54,7 @@ Note that this example may create resources which cost money. Run `terraform des
5254
|------|------|
5355
| [aws_route53_health_check.failover](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_health_check) | resource |
5456
| [aws_route53_resolver_rule.sys](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_resolver_rule) | resource |
57+
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
5558

5659
## Inputs
5760

examples/complete/main.tf

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ provider "aws" {
55
locals {
66
zone_name = sort(keys(module.zones.route53_zone_zone_id))[0]
77
# zone_id = module.zones.route53_zone_zone_id["terraform-aws-modules-example.com"]
8+
9+
vpc_cidr = "10.0.0.0/16"
10+
azs = slice(data.aws_availability_zones.available.names, 0, 3)
811
}
912

1013
module "zones" {
@@ -282,6 +285,31 @@ module "resolver_rule_associations" {
282285
}
283286
}
284287

288+
module "resolver_endpoints" {
289+
source = "../../modules/resolver-endpoints"
290+
291+
name = "example1"
292+
direction = "INBOUND"
293+
protocols = ["Do53", "DoH"]
294+
subnet_ids = module.vpc1.private_subnets
295+
296+
vpc_id = module.vpc1.vpc_id
297+
security_group_name_prefix = "example1-sg-"
298+
security_group_ingress_cidr_blocks = [
299+
module.vpc2.vpc_cidr_block
300+
]
301+
}
302+
303+
###################
304+
# Disabled modules
305+
###################
306+
307+
module "disabled_resolver_endpoints" {
308+
source = "../../modules/resolver-endpoints"
309+
310+
create = false
311+
}
312+
285313
module "disabled_records" {
286314
source = "../../modules/records"
287315

@@ -335,12 +363,17 @@ module "cloudfront" {
335363
}
336364
}
337365

366+
data "aws_availability_zones" "available" {}
367+
338368
module "vpc1" {
339369
source = "terraform-aws-modules/vpc/aws"
340370
version = "~> 5.0"
341371

342372
name = "my-vpc-for-private-route53-zone"
343-
cidr = "10.0.0.0/16"
373+
cidr = local.vpc_cidr
374+
375+
azs = local.azs
376+
private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k)]
344377
}
345378

346379
module "vpc2" {
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Route53 Resolver Endpoints
2+
3+
This module creates Route53 Resolver Endpoints.
4+
5+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
6+
## Requirements
7+
8+
| Name | Version |
9+
|------|---------|
10+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.2 |
11+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.32 |
12+
13+
## Providers
14+
15+
| Name | Version |
16+
|------|---------|
17+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.32 |
18+
19+
## Modules
20+
21+
No modules.
22+
23+
## Resources
24+
25+
| Name | Type |
26+
|------|------|
27+
| [aws_route53_resolver_endpoint.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_resolver_endpoint) | resource |
28+
| [aws_security_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) | resource |
29+
30+
## Inputs
31+
32+
| Name | Description | Type | Default | Required |
33+
|------|-------------|------|---------|:--------:|
34+
| <a name="input_create"></a> [create](#input\_create) | Whether to create Route53 resolver endpoints | `bool` | `true` | no |
35+
| <a name="input_create_security_group"></a> [create\_security\_group](#input\_create\_security\_group) | Whether to create Security Groups for Route53 Resolver Endpoints | `bool` | `true` | no |
36+
| <a name="input_direction"></a> [direction](#input\_direction) | The resolver endpoint flow direction | `string` | `"INBOUND"` | no |
37+
| <a name="input_name"></a> [name](#input\_name) | The resolver endpoint name | `string` | `null` | no |
38+
| <a name="input_protocols"></a> [protocols](#input\_protocols) | The resolver endpoint protocols | `list(string)` | `[]` | no |
39+
| <a name="input_security_group_description"></a> [security\_group\_description](#input\_security\_group\_description) | The security group description | `string` | `null` | no |
40+
| <a name="input_security_group_ids"></a> [security\_group\_ids](#input\_security\_group\_ids) | A list of security group IDs | `list(string)` | `[]` | no |
41+
| <a name="input_security_group_ingress_cidr_blocks"></a> [security\_group\_ingress\_cidr\_blocks](#input\_security\_group\_ingress\_cidr\_blocks) | A list of CIDR blocks to allow on security group | `list(string)` | `[]` | no |
42+
| <a name="input_security_group_name"></a> [security\_group\_name](#input\_security\_group\_name) | The name of the security group | `string` | `null` | no |
43+
| <a name="input_security_group_name_prefix"></a> [security\_group\_name\_prefix](#input\_security\_group\_name\_prefix) | The prefix of the security group | `string` | `null` | no |
44+
| <a name="input_security_group_tags"></a> [security\_group\_tags](#input\_security\_group\_tags) | A map of tags for the security group | `map(string)` | `{}` | no |
45+
| <a name="input_subnet_ids"></a> [subnet\_ids](#input\_subnet\_ids) | A list of subnets where Route53 resolver endpoints will be deployed | `list(string)` | `[]` | no |
46+
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags for the Route53 resolver endpoint | `map(string)` | `{}` | no |
47+
| <a name="input_type"></a> [type](#input\_type) | The resolver endpoint IP type | `string` | `"IPV4"` | no |
48+
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | The VPC ID for all the Route53 Resolver Endpoints | `string` | `""` | no |
49+
50+
## Outputs
51+
52+
| Name | Description |
53+
|------|-------------|
54+
| <a name="output_route53_resolver_endpoint_arn"></a> [route53\_resolver\_endpoint\_arn](#output\_route53\_resolver\_endpoint\_arn) | The ARN of the Resolver Endpoint |
55+
| <a name="output_route53_resolver_endpoint_host_vpc_id"></a> [route53\_resolver\_endpoint\_host\_vpc\_id](#output\_route53\_resolver\_endpoint\_host\_vpc\_id) | The VPC ID used by the Resolver Endpoint |
56+
| <a name="output_route53_resolver_endpoint_id"></a> [route53\_resolver\_endpoint\_id](#output\_route53\_resolver\_endpoint\_id) | The ID of the Resolver Endpoint |
57+
| <a name="output_route53_resolver_endpoint_ip_addresses"></a> [route53\_resolver\_endpoint\_ip\_addresses](#output\_route53\_resolver\_endpoint\_ip\_addresses) | Resolver Endpoint IP Addresses |
58+
| <a name="output_route53_resolver_endpoint_security_group_ids"></a> [route53\_resolver\_endpoint\_security\_group\_ids](#output\_route53\_resolver\_endpoint\_security\_group\_ids) | Security Group IDs mapped to Resolver Endpoint |
59+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

modules/resolver-endpoints/main.tf

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
locals {
2+
security_group_ids = var.create && var.create_security_group ? [aws_security_group.this[0].id] : var.security_group_ids
3+
}
4+
5+
resource "aws_route53_resolver_endpoint" "this" {
6+
count = var.create ? 1 : 0
7+
8+
name = var.name
9+
direction = var.direction
10+
11+
resolver_endpoint_type = var.type
12+
security_group_ids = local.security_group_ids
13+
14+
dynamic "ip_address" {
15+
for_each = var.subnet_ids
16+
17+
content {
18+
subnet_id = ip_address.value
19+
}
20+
}
21+
22+
protocols = var.protocols
23+
24+
tags = var.tags
25+
}
26+
27+
resource "aws_security_group" "this" {
28+
count = var.create && var.create_security_group ? 1 : 0
29+
30+
name = var.security_group_name_prefix == null ? coalesce(var.security_group_name, var.name) : null
31+
name_prefix = var.security_group_name_prefix
32+
description = var.security_group_description
33+
vpc_id = var.vpc_id
34+
35+
dynamic "ingress" {
36+
for_each = toset(["tcp", "udp"])
37+
38+
content {
39+
description = "Allow DNS"
40+
protocol = ingress.value
41+
from_port = 53
42+
to_port = 53
43+
cidr_blocks = var.security_group_ingress_cidr_blocks
44+
}
45+
}
46+
47+
egress {
48+
description = "Allow All"
49+
protocol = "-1"
50+
from_port = 0
51+
to_port = 0
52+
cidr_blocks = ["0.0.0.0/0"]
53+
}
54+
55+
tags = var.security_group_tags
56+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
output "route53_resolver_endpoint_id" {
3+
description = "The ID of the Resolver Endpoint"
4+
value = try(aws_route53_resolver_endpoint.this[0].id, null)
5+
}
6+
7+
output "route53_resolver_endpoint_arn" {
8+
description = "The ARN of the Resolver Endpoint"
9+
value = try(aws_route53_resolver_endpoint.this[0].arn, null)
10+
}
11+
12+
output "route53_resolver_endpoint_host_vpc_id" {
13+
description = "The VPC ID used by the Resolver Endpoint"
14+
value = try(aws_route53_resolver_endpoint.this[0].host_vpc_id, null)
15+
}
16+
17+
output "route53_resolver_endpoint_security_group_ids" {
18+
description = "Security Group IDs mapped to Resolver Endpoint"
19+
value = try(aws_route53_resolver_endpoint.this[0].security_group_ids, null)
20+
}
21+
22+
output "route53_resolver_endpoint_ip_addresses" {
23+
description = "Resolver Endpoint IP Addresses"
24+
value = try(aws_route53_resolver_endpoint.this[0].ip_address, null)
25+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
variable "create" {
2+
description = "Whether to create Route53 resolver endpoints"
3+
type = bool
4+
default = true
5+
}
6+
7+
variable "name" {
8+
description = "The resolver endpoint name"
9+
type = string
10+
default = null
11+
}
12+
13+
variable "protocols" {
14+
description = "The resolver endpoint protocols"
15+
type = list(string)
16+
default = []
17+
}
18+
19+
variable "direction" {
20+
description = "The resolver endpoint flow direction"
21+
type = string
22+
default = "INBOUND"
23+
}
24+
25+
variable "type" {
26+
description = "The resolver endpoint IP type"
27+
type = string
28+
default = "IPV4"
29+
}
30+
31+
variable "subnet_ids" {
32+
description = "A list of subnets where Route53 resolver endpoints will be deployed"
33+
type = list(string)
34+
default = []
35+
}
36+
37+
variable "security_group_ids" {
38+
description = "A list of security group IDs"
39+
type = list(string)
40+
default = []
41+
}
42+
43+
variable "tags" {
44+
description = "A map of tags for the Route53 resolver endpoint"
45+
type = map(string)
46+
default = {}
47+
}
48+
49+
# Security Group
50+
51+
variable "create_security_group" {
52+
description = "Whether to create Security Groups for Route53 Resolver Endpoints"
53+
type = bool
54+
default = true
55+
}
56+
57+
variable "vpc_id" {
58+
description = "The VPC ID for all the Route53 Resolver Endpoints"
59+
type = string
60+
default = ""
61+
}
62+
63+
variable "security_group_name" {
64+
description = "The name of the security group"
65+
type = string
66+
default = null
67+
}
68+
69+
variable "security_group_name_prefix" {
70+
description = "The prefix of the security group"
71+
type = string
72+
default = null
73+
}
74+
75+
variable "security_group_description" {
76+
description = "The security group description"
77+
type = string
78+
default = null
79+
}
80+
81+
variable "security_group_ingress_cidr_blocks" {
82+
description = "A list of CIDR blocks to allow on security group"
83+
type = list(string)
84+
default = []
85+
}
86+
87+
variable "security_group_tags" {
88+
description = "A map of tags for the security group"
89+
type = map(string)
90+
default = {}
91+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.3.2"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 5.32"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)