Skip to content

Commit 118d6bc

Browse files
committed
feat: support the feature of enabling dns request logging on the vpc resolver
1 parent becc5d5 commit 118d6bc

File tree

4 files changed

+61
-5
lines changed

4 files changed

+61
-5
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,22 @@ module "vpc" {
150150
}
151151
```
152152

153+
## Enable DNS Request Logging
154+
155+
To enable DNS request logging in your VPC, you can use the `enable_dns_request_logging` variable. This feature allows you to log DNS queries made within your VPC, which can be useful for monitoring and troubleshooting.
156+
157+
Here is an example configuration:
158+
159+
```hcl
160+
module "vpc" {
161+
source = "appvia/network/aws"
162+
version = "0.0.8"
163+
164+
enable_dns_request_logging = true
165+
# ... other configuration ...
166+
}
167+
```
168+
153169
## Using Route53 Resolver Rules
154170

155171
The module supports automatically associating shared Route53 Resolver Rules with your VPC. By default, any resolver rules shared with your account will be automatically associated. Here are some configuration examples:
@@ -229,8 +245,10 @@ The `terraform-docs` utility is used to generate this README. Follow the below s
229245
| <a name="input_name"></a> [name](#input\_name) | Is the name of the network to provision | `string` | n/a | yes |
230246
| <a name="input_tags"></a> [tags](#input\_tags) | Tags to apply to all resources | `map(string)` | n/a | yes |
231247
| <a name="input_availability_zones"></a> [availability\_zones](#input\_availability\_zones) | The number of availability zone the network should be deployed into | `number` | `2` | no |
248+
| <a name="input_dns_query_log_retention"></a> [dns\_query\_log\_retention](#input\_dns\_query\_log\_retention) | The number of days to retain DNS query logs | `number` | `7` | no |
232249
| <a name="input_enable_default_route_table_association"></a> [enable\_default\_route\_table\_association](#input\_enable\_default\_route\_table\_association) | Indicates the transit gateway default route table should be associated with the subnets | `bool` | `true` | no |
233250
| <a name="input_enable_default_route_table_propagation"></a> [enable\_default\_route\_table\_propagation](#input\_enable\_default\_route\_table\_propagation) | Indicates the transit gateway default route table should be propagated to the subnets | `bool` | `true` | no |
251+
| <a name="input_enable_dns_request_logging"></a> [enable\_dns\_request\_logging](#input\_enable\_dns\_request\_logging) | Enable logging of DNS requests | `bool` | `false` | no |
234252
| <a name="input_enable_private_endpoints"></a> [enable\_private\_endpoints](#input\_enable\_private\_endpoints) | Indicates the network should provision private endpoints | `list(string)` | `[]` | no |
235253
| <a name="input_enable_route53_resolver_rules"></a> [enable\_route53\_resolver\_rules](#input\_enable\_route53\_resolver\_rules) | Automatically associates any shared route53 resolver rules with the VPC | `bool` | `true` | no |
236254
| <a name="input_enable_ssm"></a> [enable\_ssm](#input\_enable\_ssm) | Indicates we should provision SSM private endpoints | `bool` | `false` | no |

data.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11

22
## Get the current region
33
data "aws_region" "current" {}
4+
45
## Find the current account id
56
data "aws_caller_identity" "current" {}
7+
68
## Find any forwarding rules which have been shared to us
79
data "aws_route53_resolver_rules" "current" {
810
rule_type = "FORWARD"
911
share_status = "SHARED_WITH_ME"
1012
}
11-

main.tf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,31 @@ module "vpc" {
1717
vpc_ipv4_netmask_length = var.vpc_netmask
1818
}
1919

20+
## Enable DNS request logging if required
21+
resource "aws_cloudwatch_log_group" "dns_query_logs" {
22+
count = var.enable_dns_request_logging ? 1 : 0
23+
24+
name = "/aws/route53/${var.name}/dns-query-logs"
25+
retention_in_days = var.dns_query_log_retention
26+
tags = var.tags
27+
}
28+
29+
## Create the DNS query log config
30+
resource "aws_route53_resolver_query_log_config" "dns_query_log_config" {
31+
count = var.enable_dns_request_logging ? 1 : 0
32+
33+
name = "${var.name}-dns-query-logs"
34+
destination_arn = aws_cloudwatch_log_group.dns_query_logs[0].arn
35+
}
36+
37+
## Associate the DNS query log config with the VPC
38+
resource "aws_route53_resolver_query_log_config_association" "dns_query_log_association" {
39+
count = var.enable_dns_request_logging ? 1 : 0
40+
41+
resolver_query_log_config_id = aws_route53_resolver_query_log_config.dns_query_log_config[0].id
42+
resource_id = module.vpc.vpc_attributes.id
43+
}
44+
2045
## Associate any resolver rules with the vpc if required
2146
resource "aws_route53_resolver_rule_association" "vpc_associations" {
2247
for_each = var.enable_route53_resolver_rules ? toset(local.resolver_rules) : null

variables.tf

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ variable "availability_zones" {
44
default = 2
55
}
66

7-
variable "subnets" {
8-
description = "Additional subnets to create in the network, keyed by the subnet name"
9-
type = any
10-
default = {}
7+
variable "dns_query_log_retention" {
8+
description = "The number of days to retain DNS query logs"
9+
type = number
10+
default = 7
1111
}
1212

1313
variable "enable_route53_resolver_rules" {
@@ -40,6 +40,12 @@ variable "enable_default_route_table_propagation" {
4040
default = true
4141
}
4242

43+
variable "enable_dns_request_logging" {
44+
description = "Enable logging of DNS requests"
45+
type = bool
46+
default = false
47+
}
48+
4349
variable "enable_transit_gateway_appliance_mode" {
4450
description = "Indicates the network should be connected to a transit gateway in appliance mode"
4551
type = bool
@@ -111,6 +117,12 @@ variable "transit_gateway_routes" {
111117
}
112118
}
113119

120+
variable "subnets" {
121+
description = "Additional subnets to create in the network, keyed by the subnet name"
122+
type = any
123+
default = {}
124+
}
125+
114126
variable "vpc_cidr" {
115127
description = "An optional cidr block to assign to the VPC (if not using IPAM)"
116128
type = string

0 commit comments

Comments
 (0)