Skip to content

Commit 24cc1fa

Browse files
authored
feat: setup AWS Shield Advanced (#607)
Add configuration to setup AWS Shield Advanced protection for the CloudFront distribution and Route53 hosted zone.
1 parent 57cd1fe commit 24cc1fa

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

terragrunt/aws/alarms/inputs.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ variable "route53_health_check_api_id" {
88
type = string
99
}
1010

11+
variable "route53_hosted_zone_id" {
12+
description = "ID of the Route53 hosted zone"
13+
type = string
14+
}
15+
1116
variable "s3_scan_object_log_group_name" {
1217
description = "CloudWatch log group name for the S3 scan object lambda function"
1318
type = string
@@ -50,7 +55,6 @@ variable "sentinel_shared_key" {
5055
description = "Sentinel customer ID"
5156
}
5257

53-
5458
variable "slack_webhook_url" {
5559
description = "Slack webhook URL that will be used to send notifications"
5660
type = string
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
resource "aws_shield_protection" "cloudfront_api" {
2+
name = "CloudFrontAPI"
3+
resource_arn = "arn:aws:cloudfront::${var.account_id}:distribution/${var.api_cloudfront_distribution_id}"
4+
5+
tags = {
6+
CostCentre = var.billing_code
7+
Terraform = true
8+
}
9+
}
10+
11+
resource "aws_shield_protection" "route53_hosted_zone" {
12+
name = "Route53HostedZone"
13+
resource_arn = "arn:aws:route53:::hostedzone/${var.route53_hosted_zone_id}"
14+
15+
tags = {
16+
CostCentre = var.billing_code
17+
Terraform = true
18+
}
19+
}
20+
21+
resource "aws_shield_protection_health_check_association" "cloudfront_api" {
22+
health_check_arn = "arn:aws:route53:::healthcheck/${var.route53_health_check_api_id}"
23+
shield_protection_id = aws_shield_protection.cloudfront_api.id
24+
}

terragrunt/env/production/alarms/terragrunt.hcl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@ terraform {
33
}
44

55
dependencies {
6-
paths = ["../api", "../s3_scan_object"]
6+
paths = ["../hosted_zone", "../api", "../s3_scan_object"]
7+
}
8+
9+
dependency "hosted_zone" {
10+
config_path = "../hosted_zone"
11+
12+
mock_outputs_allowed_terraform_commands = ["init", "fmt", "validate", "plan", "show"]
13+
mock_outputs_merge_strategy_with_state = "shallow"
14+
mock_outputs = {
15+
hosted_zone_id = ""
16+
}
717
}
818

919
dependency "api" {
@@ -29,6 +39,8 @@ dependency "s3_scan_object" {
2939
}
3040

3141
inputs = {
42+
route53_hosted_zone_id = dependency.hosted_zone.outputs.hosted_zone_id
43+
3244
s3_scan_object_log_group_name = dependency.s3_scan_object.outputs.function_log_group_name
3345
scan_files_api_log_group_name = dependency.api.outputs.function_log_group_name
3446
route53_health_check_api_id = dependency.api.outputs.route53_health_check_api_id

terragrunt/env/staging/alarms/terragrunt.hcl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@ terraform {
33
}
44

55
dependencies {
6-
paths = ["../api", "../s3_scan_object"]
6+
paths = ["../hosted_zone", "../api", "../s3_scan_object"]
7+
}
8+
9+
dependency "hosted_zone" {
10+
config_path = "../hosted_zone"
11+
12+
mock_outputs_allowed_terraform_commands = ["init", "fmt", "validate", "plan", "show"]
13+
mock_outputs_merge_strategy_with_state = "shallow"
14+
mock_outputs = {
15+
hosted_zone_id = ""
16+
}
717
}
818

919
dependency "api" {
@@ -29,6 +39,8 @@ dependency "s3_scan_object" {
2939
}
3040

3141
inputs = {
42+
route53_hosted_zone_id = dependency.hosted_zone.outputs.hosted_zone_id
43+
3244
s3_scan_object_log_group_name = dependency.s3_scan_object.outputs.function_log_group_name
3345
scan_files_api_log_group_name = dependency.api.outputs.function_log_group_name
3446
route53_health_check_api_id = dependency.api.outputs.route53_health_check_api_id

0 commit comments

Comments
 (0)