aws_route_table_association error

383 views
Skip to first unread message

Naresh Mallidi

unread,
Feb 3, 2021, 11:07:20 AM2/3/21
to Terraform
Can someone help with error:

Error: Error creating route table association: InvalidRouteTableID.NotFound: The routeTable ID 'rtb-0208e6570f55bc571' does not exist  status code: 400, request id: ecc6960b-2351-4603-add2-60e30ca77e10

But i am able to associate it without any issue manually. It is failing only with "rt_assocation_oregon" resource.


resource "aws_route_table_association" "rt_association_oregon" {
  subnet_id      = aws_subnet.subnet_oregon_1.id
}


Full code:

#Create VPC in us-east-1
provider "aws" {
  region  = "us-east-1"
  profile = " test1"
}
#Create VPC in us-west-2
provider "aws" {
  region  = "us-west-2"
  profile = "test1"
  alias   = "west"
}
#Create VPC in us-east-1
resource "aws_vpc" "vpc_master" {
  cidr_block           = "10.0.0.0/16"
  instance_tenancy     = "default"
  enable_dns_support   = true
  enable_dns_hostnames = true

  tags = {
    Name = "master-vpc-jenkins"
  }
}

resource "aws_vpc" "vpc_master_oregon" {
  cidr_block           = "192.168.0.0/16"
  instance_tenancy     = "default"
  enable_dns_support   = true
  enable_dns_hostnames = true
  provider             = aws.west
  tags = {
    Name = "worker-vpc-jenkins"
  }
}

#Create IGW in us-east-1
resource "aws_internet_gateway" "igw" {
  vpc_id = aws_vpc.vpc_master.id

  tags = {
    Name = "master_igw"
  }
}

#Create IGW in us-west-2

resource "aws_internet_gateway" "igw-oregon" {
  vpc_id   = aws_vpc.vpc_master_oregon.id
  provider = aws.west

  tags = {
    Name = "worker_igw"
  }
}

#Create subnet # 1 in us-east-1
resource "aws_subnet" "subnet_1" {
  vpc_id            = aws_vpc.vpc_master.id
  cidr_block        = "10.0.1.0/24"
  availability_zone = data.aws_availability_zones.available.names[0]

  tags = {
    Name = "master_subnet1"
  }
}

#Create subnet in us-west-2

resource "aws_subnet" "subnet_oregon_1" {
  vpc_id     = aws_vpc.vpc_master_oregon.id
  cidr_block = "192.168.1.0/24"
  provider   = aws.west

  tags = {
    Name = "worker_subnet1"
  }
}

#Initiate Peering connection request from us-east1
resource "aws_vpc_peering_connection" "useast1_uswest2" {
  peer_vpc_id = aws_vpc.vpc_master_oregon.id
  vpc_id      = aws_vpc.vpc_master.id
  auto_accept = false
  peer_region = "us-west-2"

  tags = {
    Name = "VPC Peering between vpc_master and vpc_master_oregon"
  }
}

#Accept VPC peering request in us-west-2 from us-east-1
resource "aws_vpc_peering_connection_accepter" "accepter_peering" {
  provider                  = aws.west
  vpc_peering_connection_id = aws_vpc_peering_connection.useast1_uswest2.id
  auto_accept               = true

  tags = {
    Side = "Receiver"
  }
}

#Create route table in us-east-1
resource "aws_route_table" "internet_route" {
  vpc_id = aws_vpc.vpc_master.id
  route {
    cidr_block = "0.0.0.0/0"
    gateway_id = aws_internet_gateway.igw.id
  }
  route {
    cidr_block                = "192.168.1.0/24"
    vpc_peering_connection_id = aws_vpc_peering_connection.useast1_uswest2.id
  }
  lifecycle {
    ignore_changes = all
  }
  tags = {
    Name = "Master-Region-RT"
  }
}

resource "aws_route_table_association" "rt_assocation_east" {
  subnet_id      = aws_subnet.subnet_1.id
  route_table_id = aws_route_table.internet_route.id
}
#Create route table in us-west-2
resource "aws_route_table" "internet_route_oregon" {
  provider = aws.west
  vpc_id   = aws_vpc.vpc_master_oregon.id
  route {
    cidr_block = "0.0.0.0/0"
    gateway_id = aws_internet_gateway.igw-oregon.id
  }
  route {
    cidr_block                = "10.0.1.0/24"
    vpc_peering_connection_id = aws_vpc_peering_connection.useast1_uswest2.id
  }
  lifecycle {
    ignore_changes = all
  }
  tags = {
    Name = "Worker-Region-RT"
  }
}


resource "aws_route_table_association" "rt_association_oregon" {
  subnet_id      = aws_subnet.subnet_oregon_1.id
}

Teemu Matilainen

unread,
Feb 4, 2021, 3:27:32 PM2/4/21
to terrafo...@googlegroups.com
Hi Naresh,

Seems that you are missing the provider specification in that "rt_association_oregon" resource.

-- 
Cheers,
  - Teemu

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/b0669398-41a7-4f1e-9f6d-e65169773d9cn%40googlegroups.com.

Naresh Mallidi

unread,
Feb 9, 2021, 5:29:35 AM2/9/21
to Terraform
Thanks Teemu,  provider specification in the "rt_association_oregon" resource fixed  the issue.
Reply all
Reply to author
Forward
0 new messages