@@ -2,7 +2,6 @@ resource "aws_ecs_cluster" "this" {
22 name = var. cluster_name
33}
44
5- # extract to iam
65resource "random_pet" "name" {
76 length = 1
87 separator = " -"
@@ -22,7 +21,6 @@ resource "aws_iam_instance_profile" "this" {
2221 name = " ${ local . iam_instance_profile_name_prefix } -${ random_pet . name . id } "
2322 role = aws_iam_role. instace_role . name
2423}
25- #
2624
2725resource "aws_launch_template" "this" {
2826 name_prefix = var. launch_template_name_prefix
@@ -36,7 +34,6 @@ echo ECS_CLUSTER=${aws_ecs_cluster.this.name} >> /etc/ecs/ecs.config
3634EOF
3735 )
3836
39-
4037 network_interfaces {
4138 associate_public_ip_address = true
4239 subnet_id = var. private_subnet_ids [0 ]
5249 }
5350}
5451
55-
5652resource "aws_autoscaling_group" "this" {
5753 desired_capacity = var. auto_scaling_group_desired_capacity
5854 max_size = var. auto_scaling_group_max_size
@@ -98,6 +94,7 @@ resource "aws_ecs_service" "this" {
9894 }
9995
10096 depends_on = [
97+ aws_lb_listener_rule . events_post_rule ,
10198 aws_lb_listener_rule . default_rule ,
10299 ]
103100}
@@ -142,8 +139,6 @@ resource "aws_cloudwatch_log_group" "this" {
142139 retention_in_days = 14
143140}
144141
145-
146-
147142resource "aws_security_group" "this" {
148143 name = " ${ var . service_name } -ecs-sg"
149144 description = " ${ var . service_name } ecs security group"
@@ -200,13 +195,19 @@ resource "aws_lb_target_group" "ip_target" {
200195 }
201196}
202197
203- resource "aws_lb_listener_rule" "default_rule " {
198+ resource "aws_lb_listener_rule" "events_post_rule " {
204199 listener_arn = var. endpoint_details . lb_listener_arn
205200 priority = 10
206201
207202 condition {
208- host_header {
209- values = [var . endpoint_details . domain_url ]
203+ path_pattern {
204+ values = [" /events" ]
205+ }
206+ }
207+
208+ condition {
209+ http_request_method {
210+ values = [" POST" ]
210211 }
211212 }
212213
@@ -215,3 +216,23 @@ resource "aws_lb_listener_rule" "default_rule" {
215216 target_group_arn = aws_lb_target_group. ip_target [0 ]. arn
216217 }
217218}
219+
220+ resource "aws_lb_listener_rule" "default_rule" {
221+ listener_arn = var. endpoint_details . lb_listener_arn
222+ priority = 20
223+
224+ condition {
225+ path_pattern {
226+ values = [" /*" ]
227+ }
228+ }
229+
230+ action {
231+ type = " fixed-response"
232+ fixed_response {
233+ content_type = " text/plain"
234+ message_body = " Not Found"
235+ status_code = " 404"
236+ }
237+ }
238+ }
0 commit comments