banzaicloud/terraform-provider-k8s

Apply from a CRD URL?

marcellodesales opened this issue · 1 comments

Is your feature request related to a problem? Please describe.

I'd like to apply from a CRD URL...

Describe the solution you'd like to see

kubectl apply -k "github.com/aws/eks-charts/stable/aws-load-balancer-controller//crds?ref=master
  • For this provider, I would expect something very simple:
resource "k8s_manifest" "load_balancer_controller_crds" {
  url   = "github.com/aws/eks-charts/stable/aws-load-balancer-controller//crds?ref=master"
  namespace = kubernetes_service_account.load_balancer_controller.metadata.0.namespace
}

Describe alternatives you've considered

  1. Download all the files from the URL to a known directory
  2. Execute kubectl apply -k in the dir
vroad commented

That should be possible at least for public http URLs, with the combination of hashicorp/http provider.
Should work as long as each yaml file contain only one resource (See issue #7 for more details).

locals {
  grafana_operator_version = "0.2.5"
  grafana_operator_crd_urls = {
    grafana = "https://raw.githubusercontent.com/banzaicloud/banzai-charts/chart/grafana-operator/${local.grafana_operator_version}/grafana-operator/crds/grafana.yaml"
    grafana_dashboards = "https://raw.githubusercontent.com/banzaicloud/banzai-charts/chart/grafana-operator/${local.grafana_operator_version}/grafana-operator/crds/grafanadashboards.yaml"
    grafana_data_sources = "https://raw.githubusercontent.com/banzaicloud/banzai-charts/chart/grafana-operator/${local.grafana_operator_version}/grafana-operator/crds/grafanadatasources.yaml"
  }
}

data "http" "grafana-operator-crds" {
  for_each = local.grafana_operator_crd_urls
  url = each.value
}

resource "k8s_manifest" "grafana-operator-crds" {
  for_each = local.grafana_operator_crd_urls
  content = data.http.grafana-operator-crds[each.key].body
}