-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
123 lines (104 loc) · 2.55 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
120
121
122
123
provider "aws" {
region = "ap-southeast-1"
profile = "network-basics"
default_tags {
tags = {
Created-For = "network-basics-tutorial"
}
}
}
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = true
tags = {
Name = "main_vpc"
}
}
resource "aws_subnet" "first" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.1.0/24"
availability_zone = "ap-southeast-1a"
tags = {
Name = "first_subnet"
}
}
resource "aws_subnet" "second" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.2.0/24"
availability_zone = "ap-southeast-1a"
tags = {
Name = "second_subnet"
}
}
resource "aws_security_group" "first_instance_sg" {
name = "first_instance_sg"
vpc_id = aws_vpc.main.id
ingress = [
{
description = "Allow ICMP"
from_port = 8
to_port = 0
protocol = "icmp"
cidr_blocks = [aws_subnet.second.cidr_block]
ipv6_cidr_blocks = []
prefix_list_ids = []
security_groups = []
self = false
}
]
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "first_instance_sg"
}
}
resource "aws_instance" "first" {
ami = data.aws_ami.aml2.id
instance_type = "t3.micro"
subnet_id = aws_subnet.first.id
vpc_security_group_ids = [aws_security_group.first_instance_sg.id]
iam_instance_profile = aws_iam_instance_profile.ec2_instance_profile.name
tags = {
Name = "first_instance"
}
}
resource "aws_security_group" "second_instance_sg" {
name = "second_instance_sg"
vpc_id = aws_vpc.main.id
ingress = [
{
description = "Allow ICMP"
from_port = 8
to_port = 0
protocol = "icmp"
cidr_blocks = [aws_subnet.first.cidr_block]
ipv6_cidr_blocks = []
prefix_list_ids = []
security_groups = []
self = false
}
]
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "second_instance_sg"
}
}
resource "aws_instance" "second" {
ami = data.aws_ami.aml2.id
instance_type = "t3.micro"
subnet_id = aws_subnet.second.id
vpc_security_group_ids = [aws_security_group.second_instance_sg.id]
iam_instance_profile = aws_iam_instance_profile.ec2_instance_profile.name
tags = {
Name = "second_instance"
}
}