skip to Main Content

I need help with the following error on Terraform, when i ran terraform apply, everything seemed to have worked when I checked aws console but then I get the following error at the end:

Error: error reading Main Route Table Association (subnet-09b6d028942d15d8e): empty result
│
│   with aws_main_route_table_association.a,
│   on main.tf line 55, in resource "aws_main_route_table_association" "a":      
│   55: resource "aws_main_route_table_association" "a"{

The below is the code for the route table portion

#3. create custom route table

resource "aws_route_table" "prod-route-table" {
  vpc_id = aws_vpc.prod-vpc.id

  route {
    cidr_block = "0.0.0.0/0"
    gateway_id = aws_internet_gateway.gw.id
  }

  route {
    ipv6_cidr_block        = "::/0"
    gateway_id = aws_internet_gateway.gw.id
  }

  tags = {
    Name = "Prod"
  }
}

This is the associate subnet with route table

#5. associate subnet with route table
resource "aws_main_route_table_association" "a"{
  vpc_id         = aws_subnet.subnet-1.id
  route_table_id = aws_route_table.prod-route-table.id
}

This is the subnet portion

#4. create a subnet 
resource "aws_subnet" "subnet-1" {
  vpc_id     = aws_vpc.prod-vpc.id
  cidr_block = "10.0.1.0/24"
  availability_zone = "us-east-1a"

  tags = {
    Name = "Prod-subnet"
  }
}

Your help will be kindly appreciated. What am i doing wrong?

Thank you.

2

Answers


  1. You’re setting the attribute egress_only_gateway_id to an internet gateway resource, while it must be using an egress internet gateway resource [1].

    References:

    1. https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/egress_only_internet_gateway
    Login or Signup to reply.
  2. egress_only_gateway_id applies to only aws_egress_only_internet_gateway, not to aws_internet_gateway. So you have to create aws_egress_only_internet_gateway.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search