Skip to content

Commit 6ef6d00

Browse files
committed
refactor: extract security group values to local
1 parent e9d8805 commit 6ef6d00

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

main.tf

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ locals {
1818
"GF_DATABASE_PASSWORD" = "${module.grafana_backend_rds.master_user_secret.secret_arn}:password::"
1919
}
2020

21+
#security groups
22+
ecs_service_security_group_name = "grafana-service"
23+
ecs_service_security_group_description = "Defines ingress and egress rules for ECS Grafana Services"
24+
ecs_service_security_group_ingress_description = "Allow ingress on Grafana port from ALB"
25+
ecs_service_security_group_egress_description = "Allow all egress"
26+
27+
grafana_alb_security_group_name = "grafana-alb"
28+
grafana_alb_security_group_description = "Defines ingress and egress rules for Grafana ALB."
29+
grafana_alb_security_group_ingress_description = "Allow all ingress"
30+
grafana_alb_security_group_egress_description = "Allow all egress on Grafana port within VPC"
31+
32+
grafana_backend_rds_security_group_name = "grafana-backend"
33+
grafana_backend_rds_security_group_description = "Defines ingress and egress rules for Grafana RDS Backend instance."
34+
grafana_backend_rds_security_group_ingress_description = "Allow ingress on Postgres port from ECS Grafana Services"
35+
grafana_backend_rds_security_group_egress_description = "Allow all egress within VPC"
36+
2137
# ALB Target Groups
2238
grafana_alb_target_group_key_name = "grafana-tg"
2339

@@ -287,13 +303,13 @@ module "ecs_service_security_group" {
287303
source = "terraform-aws-modules/security-group/aws"
288304
version = "~> 5.1.2"
289305

290-
name = "grafana-service"
291-
description = "Defines ingress and egress rules for ECS Grafana Services"
306+
name = local.ecs_service_security_group_name
307+
description = local.ecs_service_security_group_description
292308
vpc_id = var.vpc_id
293309

294310
ingress_with_source_security_group_id = [
295311
{
296-
description = "Allow ingress on Grafana port from ALB"
312+
description = local.ecs_service_security_group_ingress_description
297313
from_port = local.grafana_port
298314
to_port = local.grafana_port
299315
protocol = "tcp"
@@ -303,7 +319,7 @@ module "ecs_service_security_group" {
303319

304320
egress_with_cidr_blocks = [
305321
{
306-
description = "Allow all egress"
322+
description = local.ecs_service_security_group_egress_description
307323
from_port = 0
308324
to_port = 0
309325
protocol = "-1"
@@ -316,13 +332,13 @@ module "grafana_alb_security_group" {
316332
source = "terraform-aws-modules/security-group/aws"
317333
version = "~> 5.1.2"
318334

319-
name = "grafana-alb"
320-
description = "Defines ingress and egress rules for Grafana ALB."
335+
name = local.ecs_service_security_group_name
336+
description = local.ecs_service_security_group_description
321337
vpc_id = var.vpc_id
322338

323339
ingress_with_cidr_blocks = [
324340
{
325-
description = "Allow all ingress"
341+
description = local.grafana_alb_security_group_ingress_description
326342
from_port = 0
327343
to_port = 0
328344
protocol = "-1"
@@ -332,7 +348,7 @@ module "grafana_alb_security_group" {
332348

333349
egress_with_cidr_blocks = [
334350
{
335-
description = "Allow all egress on Grafana port within VPC"
351+
description = local.grafana_alb_security_group_egress_description
336352
from_port = local.grafana_port
337353
to_port = local.grafana_port
338354
protocol = "tcp"
@@ -345,13 +361,13 @@ module "grafana_backend_rds_security_group" {
345361
source = "terraform-aws-modules/security-group/aws"
346362
version = "~> 5.1.2"
347363

348-
name = "grafana-backend"
349-
description = "Defines ingress and egress rules for Grafana RDS Backend instance."
364+
name = local.grafana_backend_rds_security_group_name
365+
description = local.grafana_backend_rds_security_group_description
350366
vpc_id = var.vpc_id
351367

352368
ingress_with_source_security_group_id = [
353369
{
354-
description = "Allow ingress on Postgres port from ECS Grafana Services"
370+
description = local.grafana_backend_rds_security_group_ingress_description
355371
from_port = local.rds_port
356372
to_port = local.rds_port
357373
protocol = "tcp"
@@ -361,7 +377,7 @@ module "grafana_backend_rds_security_group" {
361377

362378
egress_with_cidr_blocks = [
363379
{
364-
description = "Allow all egress within VPC"
380+
description = local.grafana_backend_rds_security_group_egress_description
365381
from_port = 0
366382
to_port = 0
367383
protocol = "-1"

0 commit comments

Comments
 (0)