Skip to content

Commit 016c794

Browse files
authored
Merge pull request #31 from sil-org/disable-cloudflare-sg
add option to NOT use the Cloudflare security group
2 parents f85848a + 0bf50db commit 016c794

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ variable "health_check" {
184184
}
185185
}
186186

187+
variable "use_cloudflare_sg" {
188+
description = "Use the Cloudflare security group to block all traffic except from Cloudflare."
189+
type = bool
190+
default = "true"
191+
}
192+
187193

188194
/*
189195
* Database configuration

vpc.tf

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,39 @@ module "alb" {
101101
disable_public_ipv4 = var.disable_public_ipv4
102102
internal = "false"
103103
vpc_id = module.vpc.id
104-
security_groups = [module.vpc.vpc_default_sg_id, module.cloudflare-sg.id]
105-
subnets = module.vpc.public_subnet_ids
106-
certificate_arn = data.aws_acm_certificate.default.arn
107-
tg_name = "default-${var.app_name}-${var.app_env}"
104+
security_groups = [
105+
module.vpc.vpc_default_sg_id,
106+
var.use_cloudflare_sg ? module.cloudflare-sg.id : aws_security_group.public_https.id
107+
]
108+
subnets = module.vpc.public_subnet_ids
109+
certificate_arn = data.aws_acm_certificate.default.arn
110+
tg_name = "default-${var.app_name}-${var.app_env}"
108111
}
109112

113+
114+
/*
115+
* Create security group to allow public access to HTTPS. Used when var.use_cloudflare_sg is false.
116+
*/
117+
resource "aws_security_group" "public_https" {
118+
name = "public-https"
119+
description = "Allow HTTPS traffic from public"
120+
vpc_id = module.vpc.id
121+
tags = {
122+
Name = "public-https-${local.app_name_and_env}"
123+
}
124+
}
125+
126+
resource "aws_security_group_rule" "public_https" {
127+
type = "ingress"
128+
from_port = 443
129+
to_port = 443
130+
protocol = "tcp"
131+
security_group_id = aws_security_group.public_https.id
132+
cidr_blocks = ["0.0.0.0/0"]
133+
ipv6_cidr_blocks = ["::/0"]
134+
}
135+
136+
110137
/*
111138
* Create ECS Cluster and Auto-Scaling Group
112139
* https://registry.terraform.io/modules/sil-org/ecs-asg/aws

0 commit comments

Comments
 (0)