terraform-provider-kubernetes-alpha icon indicating copy to clipboard operation
terraform-provider-kubernetes-alpha copied to clipboard

Use Existing multiple document YAML as Resource Input

Open johnlane opened this issue 3 years ago • 3 comments

Description

This is a follow-on to existing closed issue https://github.com/hashicorp/terraform-provider-kubernetes-alpha/issues/44.

Just as some feedback really, having tried using the provider to deploy MetalLB today. The install instructions provided by metallb apply two manifests using urls. One of these manifests is a multiple document yaml file.

Whilst it's possible to use the tfk8s tool to work around this issue, it would be good to (a) be able to use yaml directly and (b) allow that yaml to contain multiple documents.

Point (a) is already covered like this:

manifest = yamldecode(file("manifest.yaml"))

But the file can only contain one document. I know this limitation is mentioned on the blog post but, when working with upstream manifests, it would be good to be able to use them directly and not alter them in any way.

References

https://github.com/hashicorp/terraform-provider-kubernetes-alpha/issues/44.

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

johnlane avatar Apr 10 '21 18:04 johnlane

@johnlane hi, I believe this issue belongs upstream in the https://github.com/hashicorp/terraform repository since yamldecode is a built-in function in Terraform (https://github.com/hashicorp/terraform/blob/a9487c76740ec8481bfe839f318341f716fd5388/website/docs/language/functions/yamldecode.html.md)

aareet avatar Apr 12 '21 14:04 aareet

I think multi-document YAML support is almost essential. Most installation instructions I've come across (e.g. for CSI drivers, metrics-server, cluster autoscaler, etc) all involve multi-document YAML. I can certainly see why converting with tfk8s makes sense, but that makes upgrading to the latest third-party manifests a bit more difficult.

I've come across https://registry.terraform.io/providers/gavinbunney/kubectl/latest/docs/data-sources/kubectl_file_documents which offers multi-document YAML support, but I would also love to see it being officially supported.

I do realize it's easier said than done. One thing that would be interesting is keying the resulting sequence such that it could be used with for_each

jalaziz avatar May 02 '21 06:05 jalaziz

You could split it and use for_each like this:

resource "kubernetes_manifest" "argo" {
  provider = kubernetes-alpha 

  for_each = {
    for i, v in split("\n---\n", file("multi.yaml")) : i => yamldecode(v)
  }

  manifest = each.value
}

jrhouston avatar May 11 '21 01:05 jrhouston