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

handle manifests with multiple resources?

Open ericchiang opened this issue 7 years ago • 5 comments

ericchiang avatar Feb 03 '18 06:02 ericchiang

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?

adamdunkley avatar May 15 '18 06:05 adamdunkley

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

ericchiang avatar May 15 '18 16:05 ericchiang

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

gaui avatar Jun 21 '18 02:06 gaui

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)}"
}

andrewgeller avatar Aug 15 '18 14:08 andrewgeller

The workaround does not process the contents serially.

gordalina avatar Sep 18 '18 17:09 gordalina