forked from LinkedInLearning/learning-terraform-3087701
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
98 lines (73 loc) · 2.19 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
98
data "aws_ami" "app_ami" {
most_recent = true
filter {
name = "name"
values = [var.ami_filter.name]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = [var.ami_filter.owner] # Bitnami
}
module "blog_vpc" {
source = "terraform-aws-modules/vpc/aws"
name = var.environment.name
cidr = "${var.environment.network_prefix}.0.0/16"
azs = ["us-west-2a","us-west-2b","us-west-2c"]
public_subnets = ["${var.environment.network_prefix}.101.0/24", "${var.environment.network_prefix}.102.0/24", "${var.environment.network_prefix}.103.0/24"]
enable_nat_gateway = false
tags = {
Terraform = "true"
Environment = var.environment.name
}
}
module "blog_autoscaling" {
source = "terraform-aws-modules/autoscaling/aws"
version = "6.5.2"
name = "blog"
min_size = var.asg_min
max_size = var.asg_max
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]
instance_type = var.instance_type
image_id = data.aws_ami.app_ami.id
}
module "blog_alb" {
source = "terraform-aws-modules/alb/aws"
version = "~> 6.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.13.0"
vpc_id = module.blog_vpc.vpc_id
name = "blog_sg"
ingress_rules = ["https-443-tcp","http-80-tcp"]
ingress_cidr_blocks = ["0.0.0.0/0"]
egress_rules = ["all-all"]
egress_cidr_blocks = ["0.0.0.0/0"]
}