0
0
AWScloud~10 mins

NAT Gateway for private subnet internet in AWS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a NAT Gateway in a public subnet.

AWS
resource "aws_nat_gateway" "example" {
  allocation_id = aws_eip.example.[1]
  subnet_id     = aws_subnet.public.[1]
}
Drag options to blanks, or click blank then click option'
Aid
Barn
Cname
Dcidr_block
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'arn' or 'name' instead of 'id' for resource references.
Confusing subnet CIDR block with subnet ID.
2fill in blank
medium

Complete the route table entry to direct private subnet traffic to the NAT Gateway.

AWS
resource "aws_route" "private_nat" {
  route_table_id         = aws_route_table.private.[1]
  destination_cidr_block = "0.0.0.0/0"
  [1]            = aws_nat_gateway.example.id
}
Drag options to blanks, or click blank then click option'
Agateway_id
Bnat_gateway_id
Cinstance_id
Dnetwork_interface_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'gateway_id' which is for Internet Gateways.
Using 'instance_id' which is for EC2 instances.
3fill in blank
hard

Fix the error in the private subnet route table to enable internet access via NAT Gateway.

AWS
resource "aws_route" "private_route" {
  route_table_id         = aws_route_table.private.id
  destination_cidr_block = "0.0.0.0/0"
  [1]             = aws_nat_gateway.example.id
}
Drag options to blanks, or click blank then click option'
Asubnet_id
Broute_table_id
Cinternet_gateway_id
Dnat_gateway_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'gateway_id' for NAT Gateway routes.
Confusing Internet Gateway and NAT Gateway attributes.
4fill in blank
hard

Fill both blanks to create a private subnet route table that sends internet traffic through the NAT Gateway.

AWS
resource "aws_route_table" "private" {
  vpc_id = aws_vpc.main.[1]
}

resource "aws_route" "private_internet_access" {
  route_table_id         = aws_route_table.private.[2]
  destination_cidr_block = "0.0.0.0/0"
  nat_gateway_id         = aws_nat_gateway.example.id
}
Drag options to blanks, or click blank then click option'
Aid
Barn
Cname
Dcidr_block
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'arn' or 'name' instead of 'id' for resource references.
Confusing CIDR block with resource ID.
5fill in blank
hard

Fill all three blanks to associate the private subnet with the private route table and enable NAT Gateway internet access.

AWS
resource "aws_route_table_association" "private_assoc" {
  subnet_id      = aws_subnet.private.[1]
  route_table_id = aws_route_table.private.[2]
}

resource "aws_route" "private_default_route" {
  route_table_id         = aws_route_table.private.[3]
  destination_cidr_block = "0.0.0.0/0"
  nat_gateway_id         = aws_nat_gateway.example.id
}
Drag options to blanks, or click blank then click option'
Aid
Barn
Cname
Dcidr_block
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'arn' or 'name' instead of 'id' for resource references.
Confusing CIDR block with resource ID.