terraform-provider-kubectl: The "count" value depends on resource attributes that cannot be determined until apply
Hello!
I have the following Terraform code inside of a module:
data "kubectl_path_documents" "esCustomResourcesManifests" {
pattern = "modules/elasticsearch/all-in-one-1.3.0.yaml"
disable_template = true
}
resource "kubectl_manifest" "esCustomResources" {
count = length(data.kubectl_path_documents.esCustomResourcesManifests.documents)
yaml_body = element(data.kubectl_path_documents.esCustomResourcesManifests.documents, count.index)
}
When running terraform plan
, I get:
Error: Invalid count argument
on modules/elasticsearch/elasticSearch.tf line 24, in resource "kubectl_manifest" "esCustomResources":
24: count = length(data.kubectl_path_documents.esCustomResourcesManifests.documents)
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.
This does not seem to be the same as issue #58, since I am not pulling any external variables. Is there something obvious I am missing?
Versions: Terraform v0.13.5 provider registry.terraform.io/gavinbunney/kubectl v1.9.1
YAML file: https://download.elastic.co/downloads/eck/1.3.0/all-in-one.yaml
Thanks in advance for your help!
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 27
- Comments: 43 (1 by maintainers)
I managed to build a hacky workaround that might work for most of you guys… Basically I replaced the
count
source using other terraform’s built-in functions to fetch the document count…Here’s an example (taken from by previous comment:
What is happening here:
data
block is using using afileset
functionfor
loop and to support the yaml’s multi-document feature, I’m also splitting each file with\n---\n
to ensure that I only grab the correct ones.flatten
the set because in case if multi-documents, there will be arrays inside arrays.I know this is not an elegant solution and there might be other issues that I missed, but it’s better than using
-target
to get around the issue…I tested locally with multiple scenarios and for now this workaround works for me.
Any updates on this issue ? Am facing similar problem, this happens only if it is used inside a module
@gavinbunney Confirm, in my case it does not work inside a module
@gavinbunney are we doing something wrong? It seems to me like I really took the configration straight out of the documentation.
On top of that, it worked but now, with a clean state, terraform does not work because of that count…
I’ve had clean, multiple runs from 2 different modules and then suddenly got this error on the one module. Using
1.14.0
of the kubectl provider and1.2.9
for TF.