Skip to content

Commit 36bc006

Browse files
authored
Merge pull request #28 from Aswin-Vijayan/TEC-56
[TEC-56][Change] - made changes in security group variables
2 parents 9322d3e + 79a501a commit 36bc006

File tree

10 files changed

+63
-94
lines changed

10 files changed

+63
-94
lines changed

environments/dev/alb-asg/main.tf

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ module "alb-sg" {
1818
environment = var.environment
1919
owner = var.owner
2020
cost_center = var.cost_center
21-
application = var.application
22-
sg_name = var.alb_sg_name
21+
application = "${var.application}-alb"
2322
vpc_id = var.vpc_id
2423

2524
ingress_cidr_from_port = var.alb_ingress_cidr_from_port
@@ -31,7 +30,7 @@ module "alb-sg" {
3130
ingress_sg_from_port = var.alb_ingress_sg_from_port
3231
ingress_sg_to_port = var.alb_ingress_sg_to_port
3332
ingress_sg_protocol = var.alb_ingress_sg_protocol
34-
ingress_security_group_ids = var.security_group_id
33+
ingress_security_group_ids = var.ingress_security_group_ids
3534
create_ingress_sg = var.alb_create_ingress_sg
3635

3736
egress_cidr_from_port = var.alb_egress_cidr_from_port
@@ -43,7 +42,7 @@ module "alb-sg" {
4342
egress_sg_from_port = var.alb_egress_sg_from_port
4443
egress_sg_to_port = var.alb_egress_sg_to_port
4544
egress_sg_protocol = var.alb_egress_sg_protocol
46-
egress_security_group_ids = var.security_group_id
45+
egress_security_group_ids = var.egress_security_group_ids
4746
create_egress_sg = var.alb_create_egress_sg
4847
}
4948

@@ -84,7 +83,6 @@ module "instance-sg" {
8483
owner = var.owner
8584
cost_center = var.cost_center
8685
application = var.application
87-
sg_name = var.sg_name
8886
vpc_id = var.vpc_id
8987

9088
ingress_cidr_from_port = var.ingress_cidr_from_port

environments/dev/alb-asg/variables.tf

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,9 @@ variable "application" {
170170
description = "Name of the application"
171171
}
172172

173-
variable "security_group_id" {
174-
description = "List of security group IDs to attach"
175-
type = list(string)
176-
}
177-
178173
variable "ingress_cidr_block" {
179174
type = list(string)
180-
description = "CIDR blocks for EC2 security group ingress rules"
175+
description = "CIDR blocks for the security group ingress rules"
181176
}
182177

183178
variable "ingress_cidr_from_port" {
@@ -215,6 +210,12 @@ variable "ingress_sg_protocol" {
215210
description = "List of protocols for sg ingress rules"
216211
}
217212

213+
variable "ingress_security_group_ids" {
214+
type = list(string)
215+
default = [ "sg-0fe4363da3994c100" ]
216+
description = "List of Security Group ids for sg ingress rules"
217+
}
218+
218219
variable "create_ingress_sg" {
219220
type = bool
220221
description = "Enable or disable Security Groups ingress rules."
@@ -260,6 +261,12 @@ variable "egress_sg_protocol" {
260261
type = list(any)
261262
}
262263

264+
variable "egress_security_group_ids" {
265+
type = list(string)
266+
default = [ "sg-0fe4363da3994c100" ]
267+
description = "List of Security Group ids for sg egress rules"
268+
}
269+
263270
variable "create_egress_sg" {
264271
type = bool
265272
description = "Enable or disable CIDR block egress rules."
@@ -268,7 +275,7 @@ variable "create_egress_sg" {
268275

269276
variable "alb_ingress_cidr_block" {
270277
type = list(string)
271-
description = "CIDR blocks for EC2 security group ingress rules"
278+
description = "CIDR blocks for the security group ingress rules"
272279
}
273280

274281
variable "alb_ingress_cidr_from_port" {
@@ -293,17 +300,17 @@ variable "alb_create_ingress_cidr" {
293300

294301
variable "alb_ingress_sg_from_port" {
295302
type = list(number)
296-
description = "List of starting ports for sg ingress rules of the EC2 security group."
303+
description = "List of starting ports for sg ingress rules"
297304
}
298305

299306
variable "alb_ingress_sg_to_port" {
300307
type = list(number)
301-
description = "List of ending ports for sg ingress rules of the EC2 security group."
308+
description = "List of ending ports for sg ingress rules"
302309
}
303310

304311
variable "alb_ingress_sg_protocol" {
305312
type = list(any)
306-
description = "List of protocols for sg ingress rules of the EC2 security group."
313+
description = "List of protocols for sg ingress rules"
307314
}
308315

309316
variable "alb_create_ingress_sg" {
@@ -313,7 +320,7 @@ variable "alb_create_ingress_sg" {
313320

314321
variable "alb_egress_cidr_block" {
315322
type = list(string)
316-
description = "CIDR blocks for EC2 security group egress rules"
323+
description = "CIDR blocks for the security group egress rules"
317324
}
318325

319326
variable "alb_egress_cidr_from_port" {
@@ -355,13 +362,3 @@ variable "alb_create_egress_sg" {
355362
type = bool
356363
description = "Enable or disable CIDR block egress rules."
357364
}
358-
359-
variable "sg_name" {
360-
type = string
361-
description = "Name of the security group for the instance."
362-
}
363-
364-
variable "alb_sg_name" {
365-
type = string
366-
description = "Name of the security group for the instance."
367-
}

environments/dev/ec2/main.tf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ provider "aws" {
55
module "ec2" {
66
source = "../../../modules/ec2"
77
region = var.region
8-
instance_name = var.instance_name
98
ami_id = var.ami_id
109
instance_type = var.instance_type
1110
key_name = var.key_name
@@ -28,7 +27,6 @@ module "security-group" {
2827
owner = var.owner
2928
cost_center = var.cost_center
3029
application = var.application
31-
sg_name = var.sg_name
3230
vpc_id = var.vpc_id
3331

3432
ingress_cidr_from_port = var.ingress_cidr_from_port

environments/dev/ec2/variables.tf

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ variable "region" {
33
description = "Region of the EC2 instance"
44
}
55

6-
variable "instance_name" {
7-
type = string
8-
description = "Name of the EC2 instance"
9-
}
10-
116
variable "ami_id" {
127
type = string
138
description = "AMI ID of the EC2 instance"
@@ -33,11 +28,6 @@ variable "subnet_ids" {
3328
description = "Subnet IDs of the EC2 instance"
3429
}
3530

36-
variable "sg_name" {
37-
type = string
38-
description = "Security group name for the instance"
39-
}
40-
4131
variable "vpc_id" {
4232
type = string
4333
description = "VPC ID for the security group"
@@ -125,7 +115,7 @@ variable "egress_cidr_to_port" {
125115
}
126116

127117
variable "egress_cidr_protocol" {
128-
type = list(string)
118+
type = list(any)
129119
description = "List of protocols for cidr egress rules of the EC2 security group."
130120
}
131121

@@ -145,7 +135,7 @@ variable "egress_sg_to_port" {
145135
}
146136

147137
variable "egress_sg_protocol" {
148-
type = list(string)
138+
type = list(any)
149139
description = "List of protocols for sg egress rules of the EC2 security group."
150140
}
151141

modules/ec2/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ resource "aws_instance" "ec2_instance" {
1010

1111
tags = merge(
1212
{
13-
Name = "${var.environment[0]}-${var.application}"
14-
Environment = var.environment[0]
13+
Name = "${var.owner}-Instance"
14+
Environment = var.environment
1515
Owner = var.owner
1616
CostCenter = var.cost_center
1717
Application = var.application

modules/ec2/variables.tf

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ variable "region" {
33
description = "Region of the ec2 instance"
44
}
55

6-
variable "instance_name" {
7-
type = string
8-
description = "Name of the ec2 instance"
9-
}
10-
116
variable "ami_id" {
127
type = string
138
description = "AMI Id of the ec2 instance"
@@ -45,7 +40,7 @@ variable "name" {
4540
}
4641

4742
variable "environment" {
48-
type = list(string)
43+
type = string
4944
description = "The environment name for the resources."
5045
}
5146

modules/security-group/main.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resource "aws_security_group" "instance_sg" {
2-
name = var.sg_name
2+
name = "${var.environment}-${var.application}"
33
description = "Security Group for Instance"
44
vpc_id = var.vpc_id
55

@@ -49,11 +49,11 @@ resource "aws_security_group" "instance_sg" {
4949

5050
tags = merge(
5151
{
52-
"Name" = "${var.name}-sg"
53-
"Environment" = var.environment
54-
"Owner" = var.owner
55-
"CostCenter" = var.cost_center
56-
"Application" = var.application
52+
Name = "${var.environment}-${var.application}"
53+
Environment = var.environment
54+
Owner = var.owner
55+
CostCenter = var.cost_center
56+
Application = var.application
5757
},
5858
var.tags
5959
)

modules/security-group/variables.tf

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ variable "region" {
33
description = "Region of the security group."
44
}
55

6-
variable "sg_name" {
7-
type = string
8-
description = "Name of the security group for the instance."
9-
}
10-
116
variable "vpc_id" {
127
type = string
138
description = "ID of the VPC associated with the security group."
@@ -81,6 +76,7 @@ variable "ingress_sg_protocol" {
8176

8277
variable "ingress_security_group_ids" {
8378
type = list(string)
79+
default = [ "sg-0fe4363da3994c100" ]
8480
description = "List of Security Group ids for sg ingress rules of the EC2 security group."
8581
}
8682

@@ -95,7 +91,7 @@ variable "egress_cidr_to_port" {
9591
}
9692

9793
variable "egress_cidr_protocol" {
98-
type = list(string)
94+
type = list(any)
9995
description = "List of protocols for cidr egress rules of the EC2 security group."
10096
}
10197

@@ -115,12 +111,13 @@ variable "egress_sg_to_port" {
115111
}
116112

117113
variable "egress_sg_protocol" {
118-
type = list(string)
114+
type = list(any)
119115
description = "List of protocols for sg egress rules of the EC2 security group."
120116
}
121117

122118
variable "egress_security_group_ids" {
123119
type = list(string)
120+
default = [ "sg-0fe4363da3994c100" ]
124121
description = "List of Security Group ids for sg egress rules of the EC2 security group."
125122
}
126123

vars/dev/alb-asg.tfvars

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ loadbalancer_type = "application"
66
alb_subnets = ["subnet-058a7514ba8adbb07", "subnet-0dbcd1ac168414927", "subnet-032f5077729435858"]
77

88
#alb-sg
9-
alb_sg_name = "alb-sg"
109
alb_ingress_cidr_from_port = [80]
1110
alb_ingress_cidr_to_port = [80]
1211
alb_ingress_cidr_protocol = ["tcp"]
@@ -29,10 +28,7 @@ alb_egress_sg_to_port = [0]
2928
alb_egress_sg_protocol = ["-1"]
3029
alb_create_egress_sg = false
3130

32-
security_group_id = ["sg-0aa656667277a3e65"]
33-
3431
# instance sg
35-
sg_name = "asg-sg"
3632
ingress_cidr_from_port = [80]
3733
ingress_cidr_to_port = [80]
3834
ingress_cidr_protocol = ["tcp"]

vars/dev/ec2.tfvars

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,45 @@
11
# EC2 Instance Variables
2-
region = "eu-north-1"
3-
instance_name = "Instance"
4-
ami_id = "ami-0989fb15ce71ba39e"
5-
instance_type = "t3.micro"
2+
region = "us-west-2"
3+
ami_id = "ami-03f65b8614a860c29"
4+
instance_type = "t2.micro"
65
key_name = "techiescamp"
76
instance_count = 1
8-
subnet_ids = ["subnet-07fab58fa9620dfb9",
9-
"subnet-051fbcbaa925b8c44",
10-
"subnet-0c46e29a23c5ba3b8"]
7+
subnet_ids = ["subnet-058a7514ba8adbb07", "subnet-04b1f595ef8c29542", "subnet-032f5077729435858"]
118

129
# EC2 Security Group Variables
13-
sg_name = "Instance_sg"
14-
vpc_id = "vpc-07d73d0c9081754d0"
10+
vpc_id = "vpc-0a5ca4a92c2e10163"
1511

1612
# Tag Keys
17-
name = "Instance"
18-
owner = "Techiescamp"
19-
environment = "dev"
20-
cost_center = "project"
21-
application = "web-app"
13+
name = ""
14+
owner = "techiescamp"
15+
environment = ""
16+
cost_center = "techiescamp-commerce"
17+
application = ""
2218

23-
# Security Group Ingress Variables
19+
# CIDR Ingress Variables
20+
create_ingress_cidr = true
2421
ingress_cidr_from_port = [22]
2522
ingress_cidr_to_port = [22]
2623
ingress_cidr_protocol = ["tcp"]
2724
ingress_cidr_block = ["10.10.0.0/16"]
28-
create_ingress_cidr = false
2925

26+
# Security Group Ingress Variables
27+
create_ingress_sg = false
3028
ingress_sg_from_port = [80]
3129
ingress_sg_to_port = [80]
3230
ingress_sg_protocol = ["tcp"]
33-
ingress_security_group_ids = ["sg-0aa656667277a3e65"]
34-
create_ingress_sg = false
31+
ingress_security_group_ids = ["sg-0fe4363da3994c100"]
3532

36-
# Security Group Egress Variables
37-
egress_cidr_from_port = [443]
38-
egress_cidr_to_port = [443]
39-
egress_cidr_protocol = ["tcp"]
40-
egress_cidr_block = ["10.20.0.0/16"]
41-
create_egress_cidr = false
33+
# CIDR Egress Variables
34+
create_egress_cidr = true
35+
egress_cidr_from_port = [0]
36+
egress_cidr_to_port = [0]
37+
egress_cidr_protocol = ["-1"]
38+
egress_cidr_block = ["0.0.0.0/0"]
4239

43-
egress_sg_from_port = [8080]
44-
egress_sg_to_port = [8080]
45-
egress_sg_protocol = ["tcp"]
46-
egress_security_group_ids = ["sg-0aa656667277a3e65"]
47-
create_egress_sg = false
40+
# Security Group Egress Variables
41+
create_egress_sg = false
42+
egress_sg_from_port = [0]
43+
egress_sg_to_port = [0]
44+
egress_sg_protocol = ["-1"]
45+
egress_security_group_ids = ["sg-0fe4363da3994c100"]

0 commit comments

Comments
 (0)