Skip to content

Commit a0e1c13

Browse files
committed
Refactor RDS module SG rule creation
1 parent 9a75d0f commit a0e1c13

File tree

5 files changed

+17
-38
lines changed

5 files changed

+17
-38
lines changed

comet-infrastructure/main.tf

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,12 @@ module "comet_rds" {
9898
count = var.enable_rds ? 1 : 0
9999
environment = var.environment
100100

101-
ec2_enabled = var.enable_ec2
102-
eks_enabled = var.enable_eks
103-
104101
availability_zones = var.enable_vpc ? module.comet_vpc[0].azs : var.availability_zones
105102
vpc_id = var.enable_vpc ? module.comet_vpc[0].vpc_id : var.comet_vpc_id
106103
rds_private_subnets = var.enable_vpc ? module.comet_vpc[0].private_subnets : var.comet_private_subnets
107-
rds_allow_ec2_sg = var.enable_ec2 ? module.comet_ec2[0].comet_ec2_sg_id : null
108-
rds_allow_eks_sg = var.enable_eks ? module.comet_eks[0].nodegroup_sg_id : null
104+
rds_allow_from_sg = var.enable_ec2 ? module.comet_ec2[0].comet_ec2_sg_id : (
105+
var.enable_eks ? module.comet_eks[0].nodegroup_sg_id : (
106+
var.rds_allow_from_sg))
109107
rds_engine = var.rds_engine
110108
rds_engine_version = var.rds_engine_version
111109
rds_instance_type = var.rds_instance_type

comet-infrastructure/modules/comet_rds/main.tf

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,9 @@ resource "aws_security_group" "mysql_sg" {
107107
}
108108

109109
resource "aws_vpc_security_group_ingress_rule" "mysql_port_inbound_ec2" {
110-
count = var.ec2_enabled ? 1 : 0
111110
security_group_id = aws_security_group.mysql_sg.id
112111
from_port = local.mysql_port
113112
to_port = local.mysql_port
114113
ip_protocol = "tcp"
115-
referenced_security_group_id = var.rds_allow_ec2_sg
116-
}
117-
118-
resource "aws_vpc_security_group_ingress_rule" "mysql_port_inbound_eks" {
119-
count = var.eks_enabled ? 1 : 0
120-
security_group_id = aws_security_group.mysql_sg.id
121-
from_port = local.mysql_port
122-
to_port = local.mysql_port
123-
ip_protocol = "tcp"
124-
referenced_security_group_id = var.rds_allow_eks_sg
114+
referenced_security_group_id = var.rds_allow_from_sg
125115
}

comet-infrastructure/modules/comet_rds/variables.tf

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
variable "environment" {
22
description = "Deployment environment, i.e. dev/stage/prod, etc"
33
type = string
4-
default = "dev"
54
}
65

76
variable "availability_zones" {
@@ -19,13 +18,8 @@ variable "rds_private_subnets" {
1918
type = list(string)
2019
}
2120

22-
variable "rds_allow_ec2_sg" {
23-
description = "Security group associated with EC2 compute, if provisioned"
24-
type = string
25-
}
26-
27-
variable "rds_allow_eks_sg" {
28-
description = "Security group associated with EKS compute, if provisioned"
21+
variable "rds_allow_from_sg" {
22+
description = "Security group from which to allow connections to RDS, for use when provisioning in existing VPC"
2923
type = string
3024
}
3125

@@ -77,16 +71,4 @@ variable "rds_database_name" {
7771
variable "rds_root_password" {
7872
description = "Root password for RDS database"
7973
type = string
80-
}
81-
82-
variable "ec2_enabled" {
83-
description = "Indicates if EC2 compute has been provisioned for Comet"
84-
type = bool
85-
default = null
86-
}
87-
88-
variable "eks_enabled" {
89-
description = "Indicates if EKS compute has been provisioned for Comet"
90-
type = bool
91-
default = null
9274
}

comet-infrastructure/terraform.tfvars

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@ enable_s3 = false
99
region = "us-east-1"
1010
environment = "prod"
1111

12-
# if not using enable_vpc to provision a VPC for the Comet resources, set the variables below to specify the existing VPC
12+
# if not using comet_vpc to provision a VPC for the Comet resources, set the variables below to specify the existing VPC
1313
comet_vpc_id = "vpc-012345abcdefghijkl"
1414
availability_zones = ["us-east-1a", "us-east-1b", "us-east-1c"]
1515
comet_public_subnets = ["subnet-012345abcdefghijkl", "subnet-012345abcdefghijkl", "subnet-012345abcdefghijkl"]
1616
comet_private_subnets = ["subnet-012345abcdefghijkl", "subnet-012345abcdefghijkl", "subnet-012345abcdefghijkl"]
1717

18-
# if provisioning ElastiCache in existing VPC, set the variable below to specify an SG that connections will be allowed from
18+
# if provisioning comet_elasticache in existing VPC, set the variable below to specify an SG that connections will be allowed from
1919
elasticache_allow_from_sg = "sg-012345abcdefghijkl"
2020

21+
# if provisioning comet_rds in existing VPC, set the variable below to specify an SG that connections will be allowed from
22+
rds_allow_from_sg = "sg-012345abcdefghijkl"
23+
2124
s3_bucket_name = "comet-use2-bucket"
2225
rds_root_password = "CHANGE-ME"
2326
ssl_certificate_arn = ""

comet-infrastructure/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ variable "elasticache_num_cache_nodes" {
230230
}
231231

232232
#comet_rds
233+
variable "rds_allow_from_sg" {
234+
description = "Security group from which to allow connections to RDS, for use when provisioning in existing VPC"
235+
type = string
236+
default = null
237+
}
238+
233239
variable "rds_engine" {
234240
description = "Engine type for RDS database"
235241
type = string

0 commit comments

Comments
 (0)