11resource "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}
3535resource "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
5555resource "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
8585resource "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
108114resource "aws_lb_listener" "petclinic" {
0 commit comments