EKS
Terraform
Error Resolution
Cloud Infrastructure
Kubernetes

Error reading EKS Cluster couldn't find resource when running terraform plan

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

The Terraform error “couldn't find resource” while reading an EKS cluster means the AWS provider asked AWS for a cluster that does not exist from that provider's point of view. That usually comes down to one of four causes: wrong account, wrong region, wrong cluster name, or trying to read a cluster during plan before it has actually been created.

Understand Where the Read Happens

This error often appears on a data source such as aws_eks_cluster or aws_eks_cluster_auth.

hcl
data "aws_eks_cluster" "main" {
  name = var.cluster_name
}

A Terraform data source is a read against existing infrastructure. If the cluster is missing, or if it exists in another account or region, Terraform cannot invent it from the configuration and the read fails immediately.

That means the first question is simple: does the cluster already exist where this provider is looking?

Verify the Cluster Outside Terraform

Before changing HCL, confirm the cluster with the AWS CLI using the same account and region assumptions.

bash
aws sts get-caller-identity
aws configure get region
aws eks describe-cluster --name my-cluster --region us-east-1

If the CLI cannot find the cluster either, Terraform is not the real problem. The name, credentials, or region are wrong.

If the CLI succeeds but Terraform fails, compare the Terraform provider configuration with the CLI context.

Make the Provider Explicit

A lot of EKS lookup failures come from implicit provider state. Be explicit about the region and, if needed, the AWS profile.

hcl
1provider "aws" {
2  region  = "us-east-1"
3  profile = "dev"
4}
5
6data "aws_eks_cluster" "main" {
7  name = "my-cluster"
8}

If you use multiple AWS accounts or aliased providers, confirm the data source is bound to the correct one. A valid cluster in the wrong account is still “not found.”

Do Not Read a Cluster Before It Exists

A common pattern is creating EKS in one module and then immediately trying to read it through a data source in the same root configuration. That can fail during planning because data sources are for existing objects, not not-yet-created ones.

Instead of re-reading the cluster by name, prefer module outputs from the resource that creates it, or split the workflow into stages.

hcl
1module "eks" {
2  source       = "./modules/eks"
3  cluster_name = "my-cluster"
4}
5
6output "cluster_name" {
7  value = module.eks.cluster_name
8}

If another stack needs the cluster later, read it from remote state or run it after the EKS stack has already been applied.

State Drift and Deleted Clusters

Terraform state can also point at a cluster that was deleted manually or replaced outside Terraform. In that case, the configuration may still look right, but the real infrastructure no longer matches the recorded expectations.

Check whether the cluster was:

  • deleted in the AWS console
  • recreated with a different name
  • created in a different workspace or account
  • partially destroyed after a failed apply

If the state is stale, the fix may involve importing the real cluster, removing dead references from state, or recreating the resource cleanly.

An Example of a Safer Structure

A clean separation is to let one Terraform stack own the EKS cluster and let a later stack consume its outputs.

hcl
1data "terraform_remote_state" "eks" {
2  backend = "s3"
3  config = {
4    bucket = "tf-state-bucket"
5    key    = "eks/terraform.tfstate"
6    region = "us-east-1"
7  }
8}
9
10provider "kubernetes" {
11  host                   = data.terraform_remote_state.eks.outputs.cluster_endpoint
12  cluster_ca_certificate = base64decode(data.terraform_remote_state.eks.outputs.cluster_ca)
13  token                  = data.terraform_remote_state.eks.outputs.cluster_token
14}

This avoids asking AWS to look up a cluster that your current stack expects to create later.

Read the Error as a Scope Problem

The message is not usually about Kubernetes internals. It is a scope problem: Terraform asked AWS for a specific EKS cluster in a specific context and AWS said it was not there. Keep the investigation scoped to identity, region, naming, and resource lifecycle.

That mindset saves time because it stops you from debugging node groups, kubeconfig, or IAM policies before confirming the cluster lookup itself.

Common Pitfalls

The most common mistake is using the right cluster name in the wrong region or AWS profile.

Another frequent problem is using data "aws_eks_cluster" for a cluster that the same Terraform run is supposed to create. A data source cannot read something that does not exist yet.

Teams also forget about manual changes. If the cluster was renamed or deleted outside Terraform, the next plan often fails with this exact message.

Finally, avoid assuming state is correct just because the configuration file looks correct. EKS and Terraform problems are often state-and-scope problems, not syntax problems.

Summary

  • The error means Terraform asked AWS for an EKS cluster that was not visible in the current provider context.
  • Verify the cluster name, AWS account, and region outside Terraform first.
  • Make the Terraform AWS provider configuration explicit.
  • Do not use a data source to read a cluster that the same run has not created yet.
  • Check for state drift or manual infrastructure changes when the configuration seems correct.

Course illustration
Course illustration

All Rights Reserved.