-
Notifications
You must be signed in to change notification settings - Fork 988
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
Cannot Create Valid ConfigMapList #2400
Comments
Hi @squat, The You can read more here. A possible workaround here could be to use built-in Terraform functions to split multi-document YAML file into separate documents to apply them individually. I hope that helps. |
Hmm that's too bad. This limitation in the provider makes it difficult to interoperate with tooling that is standard and canonical in the ecosystem. After all,
A problem with that is that this document is not a multi-document YAML file; it's a single YAML document. |
Hey @squat! Long time no see, man! Sorry for not pitching in earlier, somehow this issue evaded me until now. Supporting *List isn't a priority because they really aren't first class resources of the API, but rather an output container (others think so too). What breaks the deal for us supporting it is that they are actually missing the ObjectMeta part of their OpenApi schema, which is also what you're seeing reported in the error (missing attribute "metadata"). Tools that handle them (like kubectl) do so with bespoke client-side logic. The bespoke part is what we're trying really hard to avoid in The fact they reinforce an anti-pattern, not allowing for 1:1 mapping of Kubernetes resources to Terraform ones, isn't helping either. Fortunately, there is a trivial way around them since Terraform can already decode YAML. data "http" "configmap_list" {
url = "https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/5fcbcc9198075da5a60b09c553e709c45f1a8c09/manifests/grafana-dashboardDefinitions.yaml"
}
locals {
configmaps = yamldecode(data.http.configmap_list.response_body).items
}
resource "kubernetes_manifest" "configmap_list" {
count = length(local.configmaps)
manifest = local.configmaps[count.index]
} Let us know whether that's a good way forward for you. Nice to hear from you again! |
Hi @alexsomesan ❤️
This makes me think that depending on Thanks for the code sample, Alex. It's definitely solvable with |
@squat I actually did a little experiment which I hope will demonstrate that *List are not real API resources. What I did is I wrote a quick Go snippet that takes that exact YAML file you shared and passes it through API machinery to decode it and then uses the client-go dynamic API client (same as So even if we wanted to support them, the API will not accept the *List payloads directly. This means that clients need to do the unpacking work before actually passing the individual resources from To further drive that point, here's a log of If I may be honest here, I think using these *List containers in automation is more trouble than it's worth. I can't see any benefit in terms of UX as they obfuscate the actual resources and make it harder for editors to comprehend them and tools to process them even in batch (with extraction of individual resources always eventually required). My personal plea is, let's just not (ab)use them. YAML is bad enough as it is. |
The workaround I found for this is to use the kubectl provider instead of this one |
Terraform Version, Provider Version and Kubernetes Version
Affected Resource(s)
Terraform Configuration Files
Debug Output
https://gist.github.com/squat/f7159c4591bd1e5d04b2957109718b2b
Steps to Reproduce
kind create cluster
kubeclt create namespace monitoring
terraform init
terraform plan
Expected Behavior
What should have happened?
I'm attempting to deploy a resource from the Kube-Prometheus project. The plan should have succeeded and in fact, when vetting this manifest with Kubeconform, everything is reported to be OK. Indeed, applying the manifest manually with
kubectl apply -f ...
works as expected.Actual Behavior
What actually happened?
The plan fails with the error:
Community Note
The text was updated successfully, but these errors were encountered: