-
Notifications
You must be signed in to change notification settings - Fork 5.9k
/
Copy pathmain.tf
101 lines (76 loc) · 2.25 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
99
100
101
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]
}
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"]
tags = {
Terraform = "true"
Environment = var.environment.name
}
}
module "blog_asg" {
source = "terraform-aws-modules/autoscaling/aws"
# Autoscaling group
name = "${var.environment.name}-blog"
min_size = var.asg_min_size
max_size = var.asg_max_size
vpc_zone_identifier = module.blog_vpc.public_subnets
target_group_arns = [module.blog_alb.target_groups["ex-instance"].arn]
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 = "9.10.0"
name = "blog-alb"
vpc_id = module.blog_vpc.vpc_id
subnets = module.blog_vpc.public_subnets
security_groups = [module.blog_sg.security_group_id]
listeners = {
ex-http-https-redirect = {
port = 80
protocol = "HTTP"
redirect = {
port = "443"
protocol = "HTTPS"
status_code = "HTTP_301"
}
}
}
target_groups = {
ex-instance = {
name_prefix = "${var.environment.name}-"
protocol = "HTTP"
port = 80
target_type = "instance"
create_attachment = false
}
}
tags = {
Environment = var.environment.name
}
}
module "blog_sg" {
source = "terraform-aws-modules/security-group/aws"
version = "5.1.2"
name = "${var.environment.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"]
}