You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行terraform plan时出现EKS集群资源未找到错误求助

解决Terraform EKS模块中aws_eks_cluster数据源找不到资源的问题

问题原因

Terraform的数据源会在**计划阶段(terraform plan)**尝试读取已存在的云资源,但你的module.eks还未创建EKS集群,此时aws_eks_cluster数据源自然找不到尚未存在的集群,从而抛出"couldn't find resource"错误。此外,配置中未正确梳理依赖关系,数据源未等待集群创建完成就执行读取操作。

解决方案

直接使用terraform-aws-modules/eks/aws模块提供的输出值,无需通过aws_eks_cluster数据源间接获取信息,这也是该模块设计的初衷。修改后的配置如下:

# 先定义EKS模块
module "eks" {
  source  = "terraform-aws-modules/eks/aws"
  version = "19.5.1"
  # 填入你的其他模块配置参数
  # ...
}

# EKS集群认证数据源,需明确依赖模块创建的集群
data "aws_eks_cluster_auth" "cluster" {
  name = module.eks.cluster_name

  depends_on = [module.eks]
}

# Kubernetes Provider直接引用EKS模块的输出
provider "kubernetes" {
  host                   = module.eks.cluster_endpoint
  cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)
  token                  = data.aws_eks_cluster_auth.cluster.token
}

补充说明

  1. terraform-aws-modules/eks/aws模块已内置输出cluster_endpoint、cluster_certificate_authority_data等关键信息,直接引用即可避免数据源的时序问题。
  2. aws_eks_cluster_auth数据源需要添加depends_on = [module.eks],确保Terraform在集群创建完成后再获取认证令牌。
  3. 若首次执行仍有问题,可分两步操作:
    • 先创建EKS集群:terraform apply -target=module.eks
    • 再执行完整部署:terraform apply

内容的提问来源于stack exchange,提问作者s00103898-276165-15433

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 11:47:17