Data is not getting cluster_name

I am trying to create EKS module with terraform. I am getting cluster info with data attribute but i am getting the following error

Error: Missing required argument

│ with data.aws_eks_cluster.myapp-cluster,
│ on eks-cluster.tf line 9, in data “aws_eks_cluster” “myapp-cluster”:
│ 9: name = module.eks.cluster_id

│ The argument “name” is required, but no definition was found.


│ Error: Missing required argument

│ with data.aws_eks_cluster_auth.myapp-cluster,
│ on eks-cluster.tf line 13, in data “aws_eks_cluster_auth” “myapp-cluster”:
│ 13: name = module.eks.cluster_id

│ The argument “name” is required, but no definition was found.

The configurations i am using are as follow

provider “kubernetes” {
#load_config_file = “false”
host = data.aws_eks_cluster.myapp-cluster.endpoint
token = data.aws_eks_cluster_auth.myapp-cluster.token
cluster_ca_certificate = base64decode(data.aws_eks_cluster.myapp-cluster.certificate_authority.0.data)
}

data “aws_eks_cluster” “myapp-cluster”{
name = module.eks.cluster_id
}

data “aws_eks_cluster_auth” “myapp-cluster” {
name = module.eks.cluster_id
}

output “cc-name” {
value = module.eks.cluster_id
}

module “eks” {
source = “terraform-aws-modules/eks/aws”
version = “19.16.0”

cluster_name = “myapp-eks-cluster”
cluster_version = “1.27”

subnet_ids = module.myapp-vpc.private_subnets
vpc_id = module.myapp-vpc.vpc_id

tags = {
environment = “development”
application = “myapp”
}

eks_managed_node_groups = [
{
instance_type = “t2.small”
name = “worker-group-1”
asg_desired_capacity = 2
},
{
instance_type = “t2.medium”
name = “worker-group-2”
asg_desired_capacity = 1
},
]
}

Hi @Bushra178,

This “eks” module seems to be setting its cluster_id output value to null, which in Terraform represents “not set”, and so assigning null to these resource arguments is the same as not setting those arguments at all.

I don’t know why the module is returning a null cluster_id. You may need to refer to that module’s documentation or source code to learn how to configure it to return a non-null cluster id.