1- # Create the VPC
21resource "aws_vpc" "app_vpc" {
32 cidr_block = var. vpc_cidr_block
43 enable_dns_hostnames = var. enable_dns_hostnames
@@ -8,7 +7,6 @@ resource "aws_vpc" "app_vpc" {
87 }
98}
109
11- # Create the internet gateway
1210resource "aws_internet_gateway" "igw" {
1311 vpc_id = aws_vpc. app_vpc . id
1412
@@ -17,7 +15,6 @@ resource "aws_internet_gateway" "igw" {
1715 }
1816}
1917
20- # Create the public subnet
2118resource "aws_subnet" "public_subnet" {
2219 vpc_id = aws_vpc. app_vpc . id
2320 cidr_block = var. vpc_public_subnets_cidr_block
@@ -27,29 +24,59 @@ resource "aws_subnet" "public_subnet" {
2724 tags = {
2825 Name = " ${ var . name_prefix } -pubsubnet"
2926 }
27+ }
28+
29+ resource "aws_subnet" "private_subnet" {
30+ vpc_id = aws_vpc. app_vpc . id
31+ cidr_block = var. vpc_private_subnets_cidr_block
32+ availability_zone = var. aws_azs
3033
34+ tags = {
35+ Name = " ${ var . name_prefix } -privsubnet"
36+ }
3137}
3238
33- # Create the route table
3439resource "aws_route_table" "public_rt" {
3540 vpc_id = aws_vpc. app_vpc . id
3641
3742 route {
3843 cidr_block = " 0.0.0.0/0"
3944 gateway_id = aws_internet_gateway. igw . id
4045 }
46+ }
47+
48+ resource "aws_route_table" "private_rt" {
49+ vpc_id = aws_vpc. app_vpc . id
50+
51+ route {
52+ cidr_block = " 0.0.0.0/0"
53+ nat_gateway_id = aws_nat_gateway. nat . id
54+ }
55+ }
56+
57+ resource "aws_eip" "natgw-ip" {
58+ domain = " vpc"
59+ }
60+
61+ resource "aws_nat_gateway" "nat" {
62+ allocation_id = aws_eip. natgw-ip . id
63+ subnet_id = aws_subnet. public_subnet . id
4164
65+ tags = {
66+ Name = " ${ var . name_prefix } -nat"
67+ }
4268}
4369
44- # Assign the public route table to the public subnet
4570resource "aws_route_table_association" "public_rt_asso" {
4671 subnet_id = aws_subnet. public_subnet . id
4772 route_table_id = aws_route_table. public_rt . id
4873}
4974
75+ resource "aws_route_table_association" "private_rt_asso" {
76+ subnet_id = aws_subnet. private_subnet . id
77+ route_table_id = aws_route_table. private_rt . id
78+ }
5079
51-
52- # Create the security group
5380resource "aws_security_group" "sg" {
5481 name = " allow_ssh_http"
5582 description = " Allow ssh http inbound traffic"
@@ -79,5 +106,18 @@ resource "aws_security_group" "sg" {
79106 cidr_blocks = [" 0.0.0.0/0" ]
80107 ipv6_cidr_blocks = [" ::/0" ]
81108 }
109+ }
110+
111+ resource "aws_security_group" "powerbi_gw_sg" {
112+ name = " powerbi-gw-sg"
113+ description = " Only allow egress traffic"
114+ vpc_id = aws_vpc. app_vpc . id
82115
116+ egress {
117+ from_port = 0
118+ to_port = 0
119+ protocol = " -1"
120+ cidr_blocks = [" 0.0.0.0/0" ]
121+ ipv6_cidr_blocks = [" ::/0" ]
122+ }
83123}
0 commit comments