File tree Expand file tree Collapse file tree 2 files changed +37
-4
lines changed
Expand file tree Collapse file tree 2 files changed +37
-4
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments