-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The "count" value depends on resource attributes that cannot be determined until apply #61
Comments
Any updates on this issue ? Am facing similar problem, this happens only if it is used inside a module |
Hi @eugeneromero my guess is the pathing isn't quite right as you need to have the data "kubectl_path_documents" "esCustomResourcesManifests" {
pattern = "${path.module}/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)
} |
Hi @gavinbunney hit the same issue:
Error in resource "kubectl_manifest" "dashboard":
The "count" value depends on resource attributes that cannot be determined |
kubectl provider is the latest one, 1.10.0 |
@gavinbunney Confirm, in my case it does not work inside a module |
I think we hit the same issue with a
Using |
There is a workaround is this not the same as #58 Although not ideal |
I don't think this is the same. As mentioned in the original post, there are no variables being set here. I am hitting the same problem inside a module:
gives:
|
I have the same issue and couldn't find any solution so far. |
Having the same issue but with
Resulting in
|
same issue
|
I'm experiencing the same issue with the code found here: https://github.com/fluxcd/terraform-provider-flux/blob/main/examples/github/main.tf.
|
The same problem manifested itself here today. Yesterday and before it was working fine. |
I had the same issue with vars. You can't reference asg_name = aws_autoscaliing_group.foo.name. |
Having same issue, only inside a module. TF 0.15.3 and 1.10.0 provider |
FYI I have a hackey workaround. Basically, I create a submodule that is its own state, that all it does it use the
then in the main flux module i can reference these YAML and
This will also serve as a nice way to upgrade the flux manifests when there is a new provider - just re-generate these files, and run terraform apply in the actual state |
Exact same problem here. Was working ysterday and now it fails with:
My code:
TF version:
|
@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... |
Same issue here... Only happens if inside a module I think I will put a file called "yaml_count.txt" and read it with tonumber(file("${module.path}/.../yaml_count.txt")) and then count all the individual yaml files and put the number there :) (until this is fixed!) |
when I run terraform apply first time, it throws the following error. |
Also having the same issue as others are experiencing using the same method that's indicated in the docs. data "kubectl_file_documents" "certmanager_crds" {
content = file("${path.module}/kubectl/certmanager-crds.yaml")
}
resource "kubectl_manifest" "certmanager-crds" {
count = length(data.kubectl_file_documents.certmanager_crds.documents)
yaml_body = element(data.kubectl_file_documents.certmanager_crds.documents, count.index)
depends_on = [kubectl_manifest.rancher-import]
}
You can run
|
I'm having the same problem here inside a module. I even tested with a slimmed down version of a single data "kubectl_path_documents" "secrets_test_hack" {
pattern = "${path.module}/k8s/secrets-test/00-namespace.yaml"
}
resource "kubectl_manifest" "secrets_test" {
count = length(data.kubectl_path_documents.secrets_test_hack.documents)
yaml_body = element(data.kubectl_path_documents.secrets_test_hack.documents, count.index)
}
|
I managed to build a hacky workaround that might work for most of you guys... Here's an example (taken from by previous comment: data "kubectl_path_documents" "secrets_test" {
pattern = "${path.module}/k8s/secrets-test/*.yaml"
}
resource "kubectl_manifest" "secrets_test" {
count = length(
flatten(
toset([
for f in fileset(".", data.kubectl_path_documents.secrets_test.pattern) : split("\n---\n", file(f))
]
)
)
)
yaml_body = element(data.kubectl_path_documents.secrets_test.documents, count.index)
} What is happening here:
I know this is not an elegant solution and there might be other issues that I missed, but it's better than using I tested locally with multiple scenarios and for now this workaround works for me. |
@calexandre I tested with terraform 1.0.5 and kubectl 1.11.3 on a fresh project and I don't reproduce this module issue.
Works in both creation and update. |
@jodem it doesn't happen always, that's why some folks are reporting the issue.. I've used this module for at least one year, and it never happened to me, until today... |
Ok @calexandre thanks for the clarification, it's a bit scary. Thanks also for providing an elegant hack to mitigate the issue. |
Thanks! I don't know about the "elegant" part ;) But the actual code, shouldn't be too different I guess... |
Yep, just started hitting this with no changes 😞. How odd. |
Hit this bug today. Very annoying. :( |
This is very strange, if I put this in a file on its own: resource "kubectl_manifest" "pixie-viziers" {
for_each = data.kubectl_file_documents.pixie-viziers.manifests
yaml_body = each.value
}
resource "kubectl_manifest" "pixie-crd" {
for_each = data.kubectl_file_documents.pixie-crd.manifests
yaml_body = each.value
}
data "kubectl_file_documents" "pixie-viziers" {
content = data.http.pixie-viziers.body
}
data "kubectl_file_documents" "pixie-crd" {
content = data.http.pixie-crd.body
}
data "http" "pixie-viziers" {
url = "https://raw.githubusercontent.com/pixie-labs/pixie/main/k8s/operator/crd/base/px.dev_viziers.yaml"
}
data "http" "pixie-crd" {
url = "https://raw.githubusercontent.com/pixie-labs/pixie/main/k8s/operator/helm/crds/olm_crd.yaml"
}
provider "kubectl" {
host = "host"
cluster_ca_certificate = "cert"
token = "token"
load_config_file = false
}
terraform {
required_version = ">= 1.0.4"
required_providers {
kubectl = {
source = "gavinbunney/kubectl"
version = ">= 1.13.1"
}
http = {
source = "hashicorp/http"
version = "2.1.0"
}
}
} it works but if I use that same code in a module, it fails with: ╷
│ Error: Invalid for_each argument
│
│ on .terraform/modules/eks/eks-init/newrelic.tf line 29, in resource "kubectl_manifest" "pixie-viziers":
│ 29: for_each = data.kubectl_file_documents.pixie-viziers.manifests
│ ├────────────────
│ │ data.kubectl_file_documents.pixie-viziers.manifests is a map of string, known only after apply
│
│ The "for_each" 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 for_each depends on.
╵
╷
│ Error: Invalid for_each argument
│
│ on .terraform/modules/eks/eks-init/newrelic.tf line 34, in resource "kubectl_manifest" "pixie-crd":
│ 34: for_each = data.kubectl_file_documents.pixie-crd.manifests
│ ├────────────────
│ │ data.kubectl_file_documents.pixie-crd.manifests is a map of string, known only after apply
│
│ The "for_each" 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 for_each depends on.
╵ |
Running into this issue not inside a module with Terraform 1.2.2. The annoying part is that this worked previously and that the use case that is seemingly being protected against (a changing # of documents based on data) is probably an atypical use case... |
This is a huge annoyance.. any word on a fix or even if it is being looked into? it seems to be escalating (with the latest 1.2.2 comment saying it wont even work if put outside of a module) |
I've had clean, multiple runs from 2 different modules and then suddenly got this error on the one module. Using |
This is fix error: Invalid count argument Caused by issue: gavinbunney/terraform-provider-kubectl#61
I'm having the same issue. I'm using it inside a module, so basically what I get is that this happens when the data needs to be updated. If I delete everything I can apply and do whatever a want with these resources, but as soon as I leave it for some time when I come back it won't work anymore. |
Oddly this just started happening to me as well, even for resources that have not been touched / modified. |
I too was able to get around this by commenting out the resources and re-enabling them. Hope it lasts. |
I'm trying out using the |
I wasn't able to use the HTTP provider to fetch the yaml, and ended up committing the yaml on VCS But it seems that using this workaround, solved the issue! |
It's back again. Sigh, I will just split out the files manually instead of using kubectl_path_documents. |
@neilrao-ey you don't need to split them, follow the workaround that I linked in my comment above! |
The workaround errors out on a windows build agent, unfortunately. I suspect it might have to do with the splitting characters used but either way I'd rather avoid the hack. Looking forward to seeing this fixed in an official capacity though. |
Any resolutions to this? |
Hi, I figured out that using See:
This looks more like an internal terraform issue. Similar to #215 I opened an issue on terraform directly: hashicorp/terraform#34391 |
So i've managed to solve this by implementing what If you have a single yaml file containing multiple resources, I did the following:
This one works by splitting the file on the And if you have a folder with multiple yaml files, I did the following:
This one works by using Hope this helps someone, or you guys. I have these running inside of a module which then I have other modules |
Hello!
I have the following Terraform code inside of a module:
When running
terraform plan
, I get: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!
The text was updated successfully, but these errors were encountered: