forked from LinkedInLearning/learning-terraform-3087701
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
99 lines (73 loc) · 1.92 KB
/
main.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
data "aws_ami" "app_ami" {
most_recent = true
filter {
name = "name"
values = ["bitnami-tomcat-*-x86_64-hvm-ebs-nami"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["979382823631"] # Bitnami
}
module "blog_vpc" {
source = "terraform-aws-modules/vpc/aws"
name = "dev"
cidr = "10.0.0.0/16"
azs = ["us-west-2a", "us-west-2b", "us-west-2c"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
enable_nat_gateway = true
tags = {
Terraform = "true"
Environment = "dev"
}
}
module "blog_autoscaling" {
source = "terraform-aws-modules/autoscaling/aws"
version = "6.5.3"
name = "blog"
min_size = 1
max_size = 2
vpc_zone_identifier = module.blog_vpc.public_subnets
target_group_arns = module.blog_alb.target_group_arns
security_groups = [module.blog_sg.security_group_id]
image_id = data.aws_ami.app_ami.id
instance_type = var.instance_type
}
module "blog_alb" {
source = "terraform-aws-modules/alb/aws"
version = "~> 8.0"
name = "blog-alb"
load_balancer_type = "application"
vpc_id = module.blog_vpc.vpc_id
subnets = module.blog_vpc.public_subnets
security_groups = [module.blog_sg.security_group_id]
target_groups = [
{
name_prefix = "blog-"
backend_protocol = "HTTP"
backend_port = 80
target_type = "instance"
}
]
http_tcp_listeners = [
{
port = 80
protocol = "HTTP"
target_group_index = 0
}
]
tags = {
Environment = "dev"
}
}
module "blog_sg" {
source = "terraform-aws-modules/security-group/aws"
version = "4.16.0"
name = "blog"
vpc_id = module.blog_vpc.vpc_id
ingress_rules = ["http-80-tcp", "https-443-tcp"]
ingress_cidr_blocks = ["0.0.0.0/0"]
egress_rules = ["all-all"]
egress_cidr_blocks = ["0.0.0.0/0"]
}