-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
78 lines (59 loc) · 1.5 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
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.16"
}
}
}
# Configure the AWS Provider
provider "aws" {
region = var.region
}
module "webserver" {
source = "./modules/webserver"
key_name = var.key_name
subnet_id = aws_subnet.subnet-webserver.id
vpc_id = aws_vpc.lamp-vpc.id
owner = var.owner
}
#Setup Network Structure
resource "aws_vpc" "lamp-vpc" {
cidr_block = "10.0.0.0/16"
tags = {
Name = "LAMP VPC"
Owner = "${var.owner}"
}
}
resource "aws_subnet" "subnet-webserver" {
vpc_id = aws_vpc.lamp-vpc.id
cidr_block = "10.0.0.0/24"
availability_zone = "eu-north-1a"
map_public_ip_on_launch = true
tags = {
Name = "subnet-webserver"
Owner = "${var.owner}"
}
}
resource "aws_subnet" "subnet-database" {
vpc_id = aws_vpc.lamp-vpc.id
cidr_block = "10.0.1.0/24"
availability_zone = "eu-north-1b"
map_public_ip_on_launch = true
tags = {
Name = "subnet-database"
Owner = "${var.owner}"
}
}
resource "aws_internet_gateway" "igw_lamp" {
vpc_id = aws_vpc.lamp-vpc.id
tags = {
Name = "LAMP - IGW"
Owner = "${var.owner}"
}
}
resource "aws_route" "rt_lamp_webserver" {
route_table_id = aws_vpc.lamp-vpc.main_route_table_id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.igw_lamp.id
}