Table of Contents

The Error

Error creating NAT Gateway: NotFound: Elastic IP address not found

What Causes This

The Elastic IP referenced doesn’t exist, the subnet is private (needs to be public), or connectivity type is misconfigured.

How to Fix It

Solution 1: Create EIP First

resource "aws_eip" "nat" {
  domain = "vpc"
}

resource "aws_nat_gateway" "main" {
  allocation_id = aws_eip.nat.id
  subnet_id     = aws_subnet.public.id  # Must be PUBLIC subnet!
}

Solution 2: Use Public Subnet

# NAT Gateway must be in a public subnet with IGW route
resource "aws_subnet" "public" {
  vpc_id                  = aws_vpc.main.id
  cidr_block              = "10.0.1.0/24"
  map_public_ip_on_launch = true
}

Solution 3: Private NAT Gateway (No EIP)

resource "aws_nat_gateway" "private" {
  connectivity_type = "private"  # No EIP needed
  subnet_id         = aws_subnet.private.id
}

Prevention Tips

  1. Pin provider versions — avoid surprise breaking changes
  2. Use CI/CD — catch errors before they hit production
  3. Test with terraform plan — always review before applying
  4. Keep Terraform updated — newer versions have better error messages
  5. Use terraform validate — catches syntax errors early

Hands-On Courses

Conclusion

This error is common and fixable. Follow the solutions above, and check our Terraform course for hands-on training that covers real-world troubleshooting scenarios.