1
+ # Create a VPC
2
+ resource "aws_vpc" "nbt_vpc" {
3
+ cidr_block = " 10.123.0.0/16"
4
+ enable_dns_hostnames = true
5
+ enable_dns_support = true
6
+
7
+ tags = {
8
+ Name = " nbt-vpc"
9
+ }
10
+ }
11
+
12
+ # Create a public subnet and referencing resource
13
+ resource "aws_subnet" "nbt_public_subnet" {
14
+ vpc_id = aws_vpc. nbt_vpc . id
15
+ cidr_block = " 10.123.1.0/24"
16
+ map_public_ip_on_launch = true
17
+ availability_zone = " eu-central-1a"
18
+
19
+ tags = {
20
+ Name = " nbt-public-subnet"
21
+ }
22
+ }
23
+
24
+ # Create an internet gateway
25
+ resource "aws_internet_gateway" "nbt_igw" {
26
+ vpc_id = aws_vpc. nbt_vpc . id
27
+
28
+ tags = {
29
+ Name = " nbt-igw"
30
+ }
31
+ }
32
+
33
+ # Create a route table
34
+ resource "aws_route_table" "nbt_public_rt" {
35
+ vpc_id = aws_vpc. nbt_vpc . id
36
+
37
+ # route {
38
+ # cidr_block = "0.0.0.0/0"
39
+ # gateway_id = aws_internet_gateway.nbt_igw.id
40
+ # }
41
+
42
+ tags = {
43
+ Name = " nbt-public-rt"
44
+ }
45
+ }
46
+
47
+ # Create a route but can be created directly in the route table
48
+ resource "aws_route" "default_route" {
49
+ route_table_id = aws_route_table. nbt_public_rt . id
50
+ destination_cidr_block = " 0.0.0.0/0"
51
+ gateway_id = aws_internet_gateway. nbt_igw . id
52
+ }
53
+
54
+ # Create a route table association
55
+ resource "aws_route_table_association" "nbt_public_assoc" {
56
+ subnet_id = aws_subnet. nbt_public_subnet . id
57
+ route_table_id = aws_route_table. nbt_public_rt . id
58
+ }
0 commit comments