-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathec2.tf
64 lines (52 loc) · 1.37 KB
/
ec2.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
# The EC2 instances and its access points
resource "aws_vpc" "main_vpc" {
cidr_block = "10.0.0.0/16"
tags = {
Name = "MainVPC"
}
}
resource "aws_subnet" "public_subnet" {
vpc_id = aws_vpc.main_vpc.id
cidr_block = "10.0.1.0/24"
availability_zone = "eu-west-3a"
map_public_ip_on_launch = true
}
resource "aws_subnet" "private_subnet" {
vpc_id = aws_vpc.main_vpc.id
cidr_block = "10.0.2.0/24"
availability_zone = "eu-west-3a"
map_public_ip_on_launch = false
}
resource "aws_security_group" "web_server_sg" {
vpc_id = aws_vpc.main_vpc.id
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_instance" "front-service" {
ami = "ami-00c71bd4d220aa22a"
instance_type = var.ec2_front_instance_type
subnet_id = aws_subnet.public_subnet.id
iam_instance_profile = aws_iam_instance_profile.bucket_reader_profile.name
tags = {
Name = "frontservice"
}
}
resource "aws_instance" "back-service" {
ami = "ami-00c71bd4d220aa22a"
instance_type = var.ec2_back_instance_type
subnet_id = aws_subnet.private_subnet.id
iam_instance_profile = aws_iam_instance_profile.bucket_writer_profile.name
tags = {
Name = "backservice"
}
}