ericchiang/terraform-provider-k8s

handle manifests with multiple resources?

Opened this issue · 5 comments

handle manifests with multiple resources?

I just bumped in to this with installing the dashboard the KOPS way. The dream would be to use HTTP to download the resource and it work: https://raw.githubusercontent.com/kubernetes/kops/master/addons/kubernetes-dashboard/v1.8.3.yaml

Error produced currently:

Error: Error applying plan:

1 error(s) occurred:

* module.paws.k8s_manifest.dashboard_deployment: 1 error(s) occurred:

* k8s_manifest.dashboard_deployment: expected to create 1 resource, got 6

Is there a workaround?

There's no workaround. Happy to accept PRs if someone get's to this before I do.

gaui commented

We only have manifests with multiple resources, so shame we can't use this.

One workaround is to use terraform to split the manifests:

data "http" "kd_manifests" {
  url = "https://raw.githubusercontent.com/kubernetes/kops/master/addons/kubernetes-dashboard/v1.8.3.yaml"
}

# replace --- with SPLIT_DELIMITER because split does not support a regex delimiter
# regex may not be perfect (eg whitespace after the dashes may be valid? or something else?)
locals {
  kd_manifests = "${split("SPLIT_DELIMITER", replace(data.http.kd_manifests.body, "/(?m:^---$)/", "SPLIT_DELIMITER"))}"
}

resource "k8s_manifest" "kd_manifest" {
  count   = "${length(local.kd_manifests)}"
  content = "${element(local.kd_manifests, count.index)}"
}

The workaround does not process the contents serially.