forked from VTechnologies-NagireddyVenna/Terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvpc.tf
109 lines (87 loc) · 1.87 KB
/
vpc.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
# Specify the provider name like AWS, Azure, GCP and More...
provider "aws" {
region = "us-east-1"
}
# Creating a vpc
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
tags = {
Name = "MyVpc_123"
}
}
# Creating a public subnet
resource "aws_subnet" "tf-sub_pub" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.10.0/24"
tags = {
Name = "tf-pub"
}
}
# Creating a Private subnet
resource "aws_subnet" "tf-sub_prv" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.9.0/24"
tags = {
Name = "tf-prv"
}
}
# Creating Internet gate way
resource "aws_internet_gateway" "gw" {
vpc_id = aws_vpc.main.id
tags = {
Name = "IGW"
}
}
# Creating a Elastic Ip
resource "aws_eip" "ip" {
vpc = true
}
# Creating a NateGateWay
resource "aws_nat_gateway" "natgateway" {
allocation_id = aws_eip.ip.id
subnet_id = aws_subnet.tf-sub_pub.id
tags = {
name = "prod_nategatway"
}
depends_on = [aws_eip.ip]
}
# Creating Public Routing Table
resource "aws_route_table" "pbr" {
vpc_id = aws_vpc.main.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.gw.id
}
tags = {
Name = "pub_toute"
}
}
# Creating Private routing Table
resource "aws_route_table" "pvrr" {
vpc_id = aws_vpc.main.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_nat_gateway.natgateway.id
}
tags = {
Name = "prv_toute"
}
}
# Creating Public server
resource "aws_instance" "pbserver" {
ami = "ami-0574da719dca65348"
instance_type = "t2.micro"
subnet_id = "subnet-0e6138836b7a702f3"
tags = {
Name = "terra-server123"
}
}
# Creating private server
resource "aws_instance" "prvserver" {
ami = "ami-0574da719dca65348"
instance_type = "t2.micro"
subnet_id = "subnet-0e6138836b7a702f3"
tags = {
Name = "terra-server1234"
}
}