A managed resource "..." "..." has not been declared in the root module

Upgraded to:
Terraform v0.12.29
(+) provider.aws v3.1.0

Keep getting error messages on managed resources.

Wondering if anyone has run into this.

Error: Reference to undeclared resource

on route.tf line 15, in resource “aws_route_table_association” “public-subnet-us-east-2-association”:
15: subnet_id = aws_subnet.public-subnet-us-east-2.id

A managed resource “aws_subnet” “public-subnet-us-east-2” has not been
declared in the root module.

Hi @surfd4wg

The file public.tf defined public-subnet-in-us-east-2:

resource "aws_subnet" "public-subnet-in-us-east-2" {
  vpc_id = aws_vpc.default.id

  cidr_block        = var.public_subnet_cidr
  availability_zone = "us-east-2a"

  tags = {
    Name = "Vault Public Subnet"
  }
} 

And the file is looking for public-subnet-us-east-2:

resource "aws_route_table_association" "public-subnet-us-east-2-association" {
  subnet_id      = aws_subnet.public-subnet-us-east-2.id
  route_table_id = aws_route_table.public-subnet-us-east-2.id
}

Rename public-subnet-in-us-east-2 to public-subnet-us-east-2 (removing -in) and edit also the reference in webserver.tf and natinstance.tf or the other way around.

1 Like