terraform-provider-kubectl icon indicating copy to clipboard operation
terraform-provider-kubectl copied to clipboard

Support for kustomize?

Open matyat opened this issue 4 years ago • 2 comments

Since kubectl supports kustomize out of the box now with the -k opt, it would be nice if this provider could work with that too.

I've put something together that more or less works for my current setup:

data "external" "kustomize" {
  program = ["./scripts/kustomize_build.sh"]

  query = {
    path = var.k8s_config_path
  }
}

data "kubectl_file_documents" "kustomize" {
  content = data.external.kustomize.result.rendered
}

resource "kubectl_manifest" "app" {
  for_each = toset(data.kubectl_file_documents.kustomize.documents)

  yaml_body = each.value
}

Where kustomize_build.sh is:

#! /bin/sh

set -o errexit

path=$(jq -r .path /dev/stdin)

output=$(kustomize build "$path")

jq -n --arg output "$output" '{"rendered":$output}'

But just wondering if a more integrated solution is on the table? Perhaps with a kubectl_kustomize_documents data type to render a list of documents?

matyat avatar Feb 17 '21 14:02 matyat

More than happy to put a PR together if you think its a good idea.

matyat avatar Feb 17 '21 15:02 matyat

@Logibox I like that idea! It would make sense to implement it as another data_resource so you could preview the generated yaml. Happy to review a PR if you have some time to look into implementation :)

gavinbunney avatar May 24 '21 17:05 gavinbunney