Skip to content

Commit 6c9ce84

Browse files
authored
Merge pull request #6 from Aswin-Vijayan/master
Variable changes
2 parents e134625 + 26b6137 commit 6c9ce84

File tree

2 files changed

+79
-40
lines changed

2 files changed

+79
-40
lines changed

modules/lb-asg/main.tf

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
resource "aws_iam_instance_profile" "instance_profile" {
2-
name = "instance-profile"
2+
name = var.instance_profile
33

4-
role = "instance_role"
4+
role = var.instance_roles
55
}
66

7-
resource "aws_security_group" "alb_sg" {
8-
name_prefix = "alb-sg"
7+
resource "aws_security_group" "lb_sg" {
8+
name_prefix = var.lb_security_group
99

1010
ingress {
11-
from_port = 0
12-
to_port = 65535
13-
protocol = "tcp"
14-
cidr_blocks = ["0.0.0.0/0"]
11+
from_port = var.from_port
12+
to_port = var.to_port
13+
protocol = var.protocol
14+
cidr_blocks = var.cidr_block
1515
}
1616

1717
egress {
@@ -23,43 +23,43 @@ resource "aws_security_group" "alb_sg" {
2323

2424
tags = merge(
2525
{
26-
Name = "petclinic-alb-sg",
26+
Name = "${var.name}-lb-sg",
2727
Environment = var.environment,
2828
Owner = var.owner,
2929
CostCenter = var.cost_center,
30-
Application = "pet-clinic"
30+
Application = var.application
3131
},
3232
var.tags
3333
)
3434
}
3535
resource "aws_lb" "petclinic" {
36-
name = "petclinic-alb"
37-
internal = false
38-
load_balancer_type = "application"
36+
name = "${var.name}-lb"
37+
internal = var.internal
38+
load_balancer_type = var.lb_type
3939

4040
subnets = var.subnets
4141
security_groups = [aws_security_group.alb_sg.id]
4242

4343
tags = merge(
4444
{
45-
Name = "petclinic-alb",
45+
Name = "${var.name}-lb",
4646
Environment = var.environment,
4747
Owner = var.owner,
4848
CostCenter = var.cost_center,
49-
Application = "pet-clinic"
49+
Application = var.application
5050
},
5151
var.tags
5252
)
5353
}
5454

5555
resource "aws_security_group" "instance_sg" {
56-
name_prefix = "petclinic-sg"
56+
name_prefix = var.instance_sg
5757

5858
ingress {
59-
from_port = 0
60-
to_port = 65535
61-
protocol = "tcp"
62-
cidr_blocks = ["0.0.0.0/0"]
59+
from_port = instance_from_port
60+
to_port = instance_to_port
61+
protocol = instance_protocol
62+
cidr_blocks = instance_cidr_block
6363
}
6464

6565
egress {
@@ -71,38 +71,44 @@ resource "aws_security_group" "instance_sg" {
7171

7272
tags = merge(
7373
{
74-
Name = "petclinic-sg"
74+
Name = "${var.name}-instance-sg"
7575
Environment = var.environment,
7676
Owner = var.owner,
7777
CostCenter = var.cost_center,
78-
Application = "pet-clinic"
78+
Application = var.application
7979
},
8080
var.tags
8181
)
8282
}
8383

8484

8585
resource "aws_lb_target_group" "petclinic" {
86-
name_prefix = "pc-lb"
87-
port = 8080
88-
protocol = "HTTP"
86+
name_prefix = var.target_group_name
87+
port = var.target_group_port
88+
protocol = var.target_group_protocol
8989
vpc_id = var.vpc_id
90-
target_type = "instance"
90+
target_type = var.target_type
9191

9292
health_check {
93-
path = "/"
94-
port = 8080
95-
protocol = "HTTP"
96-
interval = 30
97-
timeout = 5
98-
healthy_threshold = 2
99-
unhealthy_threshold = 2
93+
path = var.health_check_path
94+
port = var.health_check_port
95+
protocol = var.health_check_protocol
96+
interval = var.health_check_interval
97+
timeout = var.health_check_timeout
98+
healthy_threshold = var.health_check_healthy_threshold
99+
unhealthy_threshold = var.health_check_unhealthy_threshold
100100
}
101101

102-
tags = {
103-
Environment = var.environment
104-
Terraform = "true"
105-
}
102+
tags = merge(
103+
{
104+
Name = "${var.name}-lb-target-group"
105+
Environment = var.environment,
106+
Owner = var.owner,
107+
CostCenter = var.cost_center,
108+
Application = var.application
109+
},
110+
var.tags
111+
)
106112
}
107113

108114
resource "aws_lb_listener" "petclinic" {

vars/dev/lb-asg.tfvars

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,43 @@
11
region = "us-west-2"
2-
owner = "Techiescamp"
3-
environment = "dev"
4-
cost_center = "project-pet-clinic"
2+
# iam_role
3+
instance_profile = "FullAccessProfile"
4+
instance_role = "instance_role"
5+
# lb_sg
6+
lb_security_group = "lb-sg"
7+
lb_from_port = 0
8+
lb_to_port = 65535
9+
lb_protocol = "tcp"
10+
lb_cidr_block = ["0.0.0.0/0"]
11+
internal = false
12+
lb_type = "application"
13+
# insatnce_sg
14+
instance_sg = "petclinic_instance_sg"
15+
instance_from_port = 0
16+
instance_to_port = 65535
17+
instance_protocol = "tcp"
18+
instance_cidr_block = ["0.0.0.0/0"]
19+
# target_group
20+
target_group_name = "pc-lb"
21+
target_group_port = 8080
22+
target_group_protocol = "HTTP"
23+
target_type = "instance"
24+
# health_check
25+
health_check_path = "/"
26+
health_check_port = 8080
27+
health_check_protocol = "HTTP"
28+
health_check_interval = 30
29+
health_check_timeout = 5
30+
health_check_healthy_treshold = 2
31+
health_check_unhealthy_treshold = 2
32+
533
ami_id = "ami-08076abdd4bdb9b18"
634
instance_type = "t2.medium"
735
key_name = "aswin-key"
836
vpc_id = "vpc-0a5ca4a92c2e10163"
937
subnets = ["subnet-058a7514ba8adbb07", "subnet-0dbcd1ac168414927", "subnet-032f5077729435858"]
1038

39+
name = "petclinic"
40+
owner = "Techiescamp"
41+
environment = "dev"
42+
cost_center = "project-pet-clinic"
43+
application = "pet-clinic"

0 commit comments

Comments
 (0)