PureDevOps Community

Terraform Error: Invalid depends_on reference

terraform plan

│ Error: Invalid depends_on reference

│ on …/modules/vpc/main.tf line 56, in resource “aws_eip” “nat_eip”:
│ 56: depends_on = [aws_internet_gateway.ig.id]

│ References in depends_on must be to a whole object (resource, etc), not to an attribute of an object.

my resource details

resource "aws_internet_gateway" "ig" {
  vpc_id = aws_vpc.vpc.id
  tags = {
    Name        = "${var.env}-igw"
    Environment = var.env
  }
}

After few trial found that the below works

# Elastic-IP (eip) for NAT
resource "aws_eip" "nat_eip" {
  vpc        = true
  depends_on = [aws_internet_gateway.ig]
}