terraform-aws-eks
terraform-aws-eks copied to clipboard
Error when adding dependencies on building pre_bootstrap_user_data
Description
When adding a dependency from another module to build the pre_bootstrap_user_data I'm getting the following error:
β Error: Invalid count argument β β on .terraform/modules/downstream-clusters-EKS.eks/modules/_user_data/main.tf line 67, in data "cloudinit_config" "linux_eks_managed_node_group": β 67: count = var.create && var.platform == "linux" && var.is_eks_managed_node_group && !var.enable_bootstrap_user_data && var.pre_bootstrap_user_data != "" && var.user_data_template_path == "" ? 1 : 0 β β The "count" value depends on resource attributes that cannot be determined β until apply, so Terraform cannot predict how many instances will be β created. To work around this, use the -target argument to first apply only β the resources that the count depends on.
My code looks like this:
pre_bootstrap_user_data = templatefile("${path.module}/startup_script.tpl", { cluster = var.cluster-name, file_system_ids = join(" ", toset(module.efs_list[0].efs_ids)) })
My goal is to create EFS before the cluster to pass the efs_ids to the bootstrap script
- [X] β I have searched the open/closed issues and my issue is not listed.
Versions
- Module version [Required]: 19.20.0
Reproduction Code [Required]
pre_bootstrap_user_data = templatefile("${path.module}/startup_script.tpl", { cluster = var.cluster-name, file_system_ids = join(" ", toset(module.efs_list[0].efs_ids)) })
Expected behavior
No error due to adding a dependency, I would like to buils EFS before the cluster to pass the id's to the user_data
Actual behavior
β Error: Invalid count argument β β on .terraform/modules/downstream-clusters-EKS.eks/modules/_user_data/main.tf line 67, in data "cloudinit_config" "linux_eks_managed_node_group": β 67: count = var.create && var.platform == "linux" && var.is_eks_managed_node_group && !var.enable_bootstrap_user_data && var.pre_bootstrap_user_data != "" && var.user_data_template_path == "" ? 1 : 0 β β The "count" value depends on resource attributes that cannot be determined β until apply, so Terraform cannot predict how many instances will be β created. To work around this, use the -target argument to first apply only β the resources that the count depends on.
Terminal Output Screenshot(s)
Additional context
My goal is to create EFS before the cluster to pass the efs_ids to the bootstrap script
please provide a minimal reproduction
you most likely have an explicit depends_on that you should not have
thanks @bryantbiggs!
The problem is indeed the dependency, why I should not have it? I need the efs id's in my user data.
To reproduce you just need to add a dependency to another module inside the pre_bootstrap_user_data varriable.
Regards,
You don't need an explicit dependency when you have an implicit dependency - the user data won't be rendered until the EFS IDs are resolved, this is what Terraform handles automatically for you
I don't have a explicit dependency (depends_on) on my code I just have a reference to an external module (implicit dependency):
pre_bootstrap_user_data = templatefile("${path.module}/startup_script.tpl", { cluster = var.cluster-name, file_system_ids = join(" ", toset(module.efs_list[0].efs_ids)) })
The problem is that with the implicit dependency I get the following error:
β on .terraform/modules/downstream-clusters-EKS.eks/modules/_user_data/main.tf line 67, in data "cloudinit_config" "linux_eks_managed_node_group": β 67: count = var.create && var.platform == "linux" && var.is_eks_managed_node_group && !var.enable_bootstrap_user_data && var.pre_bootstrap_user_data != "" && var.user_data_template_path == "" ? 1 : 0 β β The "count" value depends on resource attributes that cannot be determined β until apply, so Terraform cannot predict how many instances will be β created. To work around this, use the -target argument to first apply only β the resources that the count depends on.
I don't have a explicit dependency (depends_on) on my code I just have a reference to an external module (implicit dependency):
I don't know that, you failed to provide a reproduction π
join(" ", toset(module.efs_list[0].efs_ids)) })
Have you tried removing the toset(), this puts a computed value into the key of a map which Terraform does not like
Hi @bryantbiggs,
I've tested removing the toset() and I'm getting the same result, I'm going to prepare the code to share with you so you can see the entire module code for a reproduction.
Thanks,
Hi @bryantbiggs,
I've prepared the code and below you can find how to reproduced it:
module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "~> 19.0"
cluster_version = "1.23"
cluster_name = var.cluster-name
control_plane_subnet_ids = compact([var.subnet-CP-az-a, var.subnet-CP-az-b])
subnet_ids = compact([var.subnet-az-a, var.subnet-az-b])
vpc_id = var.vpc-id
eks_managed_node_group_defaults = {
pre_bootstrap_user_data = templatefile("${path.module}/startup_script.tpl", { cluster = var.cluster-name, file_system_ids = join(" ", module.efs_list[0].efs_ids) })
}
eks_managed_node_groups = {
green = {
min_size = 1
max_size = 10
desired_size = 1
instance_types = ["t3.large"]
capacity_type = "SPOT"
}
}
}
This is the code for the efs-list module:
module "efs" {
source = "./efs"
kms_arn = var.kms_arn
cluster_name = var.cluster_name
vpc_id = var.vpc_id
for_each = var.efs_names
efs_name = each.value
}
This is its outputs.tf:
output "efs_ids" {
value = flatten([for efs in module.efs : efs.efs_id])
}
And this is the outputs.tf of the efs module:
output "efs_id" {
value = aws_efs_file_system.efs.id
}
The error I'm getting with this code is the following:
β Error: Invalid count argument β β on .terraform/modules/downstream-clusters-EKS.eks/modules/_user_data/main.tf line 67, in data "cloudinit_config" "linux_eks_managed_node_group": β 67: count = var.create && var.platform == "linux" && var.is_eks_managed_node_group && !var.enable_bootstrap_user_data && var.pre_bootstrap_user_data != "" && var.user_data_template_path == "" ? 1 : 0 β β The "count" value depends on resource attributes that cannot be determined β until apply, so Terraform cannot predict how many instances will be β created. To work around this, use the -target argument to first apply only β the resources that the count depends on.
Hi @bryantbiggs
I've simplified the code to just create a single EFS and do everything inside a single module but I get same error:
module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "~> 19.0"
cluster_version = "1.23"
cluster_name = var.cluster-name
control_plane_subnet_ids = compact([var.subnet-CP-az-a, var.subnet-CP-az-b])
subnet_ids = compact([var.subnet-az-a, var.subnet-az-b])
vpc_id = var.vpc-id
eks_managed_node_group_defaults = {
pre_bootstrap_user_data = templatefile("${path.module}/startup_script.tpl", { cluster = var.cluster-name, file_system_ids = module.efs[0].efs_id })
}
eks_managed_node_groups = {
green = {
min_size = 1
max_size = 10
desired_size = 1
instance_types = ["t3.large"]
capacity_type = "SPOT"
}
}
}
module "efs" {
count = var.efs_name != null ? 1 : 0
source = "./modules/efs"
efs_name = var.efs_name
kms_arn = data.aws_kms_alias.kaas_eks_kms.arn
cluster_name = var.cluster-name
vpc_id = var.vpc-id
}
output "efs_id" {
value = aws_efs_file_system.efs.id
}
β· β Error: Invalid count argument β β on .terraform/modules/downstream-clusters-EKS.eks/modules/_user_data/main.tf line 67, in data "cloudinit_config" "linux_eks_managed_node_group": β 67: count = var.create && var.platform == "linux" && var.is_eks_managed_node_group && !var.enable_bootstrap_user_data && var.pre_bootstrap_user_data != "" && var.user_data_template_path == "" ? 1 : 0 β β The "count" value depends on resource attributes that cannot be determined β until apply, so Terraform cannot predict how many instances will be β created. To work around this, use the -target argument to first apply only β the resources that the count depends on. β΅
Please re-visit the issue template requirements and see https://github.com/bryantbiggs/how-to-create-reproduction for additional details
Namely:
The reproduction MUST be executable by running
terraform init && terraform applywithout any further changes.
This issue has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this issue will be closed in 10 days
closing this for now since there isn't any action that we can take at this time
I'm going to lock this issue because it has been closed for 30 days β³. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.