forked from LinkedInLearning/learning-terraform-3087701
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
120 lines (96 loc) · 2.32 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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
}
data "aws_vpc" "default" {
default = true
}
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"]
tags = {
Terraform = "true"
Environment = "dev"
}
}
module "autoscaling" {
source = "terraform-aws-modules/autoscaling/aws"
version = "8.0.0"
# insert the 1 required variable here
name = "blog"
min_size = 1
max_size = 2
vpc_zone_identifier = module.blog_vpc.public_subnets
security_groups = [module.blog_sg.security_group_id]
image_id = data.aws_ami.app_ami.id
instance_type = var.instance_type
}
module "alb" {
source = "terraform-aws-modules/alb/aws"
name = "blog-alb"
vpc_id = module.blog_vpc.vpc_id
subnets = module.blog_vpc.public_subnets
# Security Group
security_group_ingress_rules = {
all_http = {
from_port = 80
to_port = 80
ip_protocol = "tcp"
description = "HTTP web traffic"
cidr_ipv4 = "0.0.0.0/0"
}
all_https = {
from_port = 443
to_port = 443
ip_protocol = "tcp"
description = "HTTPS web traffic"
cidr_ipv4 = "0.0.0.0/0"
}
}
security_group_egress_rules = {
all = {
ip_protocol = "-1"
cidr_ipv4 = "10.0.0.0/16"
}
}
listeners = {
ex-http-https-redirect = {
port = 80
protocol = "HTTP"
redirect = {
port = "443"
protocol = "HTTPS"
status_code = "HTTP_301"
}
}
}
tags = {
Environment = "dev"
}
}
module "blog_sg" {
source = "terraform-aws-modules/security-group/aws"
version = "5.2.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"]
}
resource "aws_security_group" "blog" {
name = "blog"
description = "Allow http and https in. Allow everything out"
vpc_id = data.aws_vpc.default.id
}