forked from antonputra/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblue.tf
43 lines (37 loc) · 1.26 KB
/
blue.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# EC2 Instance
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance
resource "aws_instance" "blue" {
count = var.enable_blue_env ? var.blue_instance_count : 0
ami = local.ubuntu_ami
instance_type = "t2.micro"
subnet_id = local.private_a_subnet_id
vpc_security_group_ids = [aws_security_group.web.id]
user_data = templatefile("./init-script.sh", {
file_content = "blue version 1.2 - ${count.index}"
})
tags = {
Name = "blue version 1.2 - ${count.index}"
}
}
# Load Balancer Target Group
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb_target_group
resource "aws_lb_target_group" "blue" {
name = "blue-tg-blue-lb"
port = 80
protocol = "HTTP"
vpc_id = local.vpc_id
health_check {
port = 80
protocol = "HTTP"
timeout = 5
interval = 10
}
}
# Load Balancer Target Group Attachment
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb_target_group_attachment
resource "aws_lb_target_group_attachment" "blue" {
count = length(aws_instance.blue)
target_group_arn = aws_lb_target_group.blue.arn
target_id = aws_instance.blue[count.index].id
port = 80
}