forked from mavrick202/terraform-functions-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
75 lines (59 loc) · 1.6 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
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" "subnets" {
vpc_id = "${aws_vpc.default.id}"
count = 3 #Count starts always from 0.
cidr_block = "${element(var.blocks, count.index)}"
availability_zone = "${element(var.azs, count.index)}"
tags {
Name = "Terraform-Subnet-${count.index+1}"
}
}
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" {
count = "${length(var.blocks)}"
subnet_id = "${element(aws_subnet.subnets.*.id, count.index)}" #"${aws_subnet.subnets.*.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"]
}
}