terraform-provider-kubectl
terraform-provider-kubectl copied to clipboard
Support for kustomize?
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?
More than happy to put a PR together if you think its a good idea.
@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 :)