forked from jayachandrareddym/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
117 lines (96 loc) · 2.54 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
provider "aws" {
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret_key}"
region = "${var.aws_region}"
}
resource "aws_vpc" "default" {
cidr_block = "${var.vpc_cidr}"
enable_dns_hostnames = true
tags = {
Name = "${var.vpc_name}"
}
}
resource "aws_internet_gateway" "default" {
vpc_id = "${aws_vpc.default.id}"
tags = {
Name = "${var.IGW_name}"
}
}
resource "aws_subnet" "subnet1-public" {
vpc_id = "${aws_vpc.default.id}"
cidr_block = "${var.public_subnet1_cidr}"
availability_zone = "us-east-1a"
tags = {
Name = "${var.public_subnet1_name}"
}
}
resource "aws_subnet" "subnet2-public" {
vpc_id = "${aws_vpc.default.id}"
cidr_block = "${var.public_subnet2_cidr}"
availability_zone = "us-east-1b"
tags = {
Name = "${var.public_subnet2_name}"
}
}
resource "aws_subnet" "subnet3-public" {
vpc_id = "${aws_vpc.default.id}"
cidr_block = "${var.public_subnet3_cidr}"
availability_zone = "us-east-1c"
tags = {
Name = "${var.public_subnet3_name}"
}
}
resource "aws_route_table" "terraform-public" {
vpc_id = "${aws_vpc.default.id}"
route {
cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.default.id}"
}
tags = {
Name = "${var.Main_Routing_Table}"
}
}
resource "aws_route_table_association" "terraform-public" {
subnet_id = "${aws_subnet.subnet1-public.id}"
route_table_id = "${aws_route_table.terraform-public.id}"
}
resource "aws_security_group" "allow_all" {
name = "allow_all"
description = "Allow all inbound traffic"
vpc_id = "${aws_vpc.default.id}"
ingress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
#data "aws_ami" "my_ami" {
# most_recent = true
# #name_regex = "^mavrick"
# owners = ["444984551434"]
#}
resource "aws_instance" "web-1" {
#ami = "${data.aws_ami.my_ami.id}"
ami = "ami-0d857ff0f5fc4e03b"
availability_zone = "us-east-1a"
instance_type = "t2.micro"
key_name = "LaptopKey"
subnet_id = "${aws_subnet.subnet1-public.id}"
vpc_security_group_ids = ["${aws_security_group.allow_all.id}"]
associate_public_ip_address = true
tags = {
Name = "Server-1"
Env = "Prod"
Owner = "Sree"
}
}
#output "ami_id" {
# value = "${data.aws_ami.my_ami.id}"
#}