kbst / terraform-provider-kustomization

Terraform provider for Kustomize
https://www.kubestack.com
Apache License 2.0
270 stars 53 forks source link

Docs `custom-manifests` example may be wrong for recent versions #229

Closed javiertury closed 1 year ago

javiertury commented 1 year ago

The example located in the following documentation page does not work for me, and I suspect it may be wrong or outdated.

https://www.kubestack.com/framework/documentation/extending-kubestack/#kubernetes-manifests

I'm referring to the usage of apps and ops properties in custom-manifests. Note that I changed version 0.3.0 to 0.4.0 because otherwise I get an error in terraform. When running terraform apply, the following module finishes "successfully" but terraform completely ignores upstream.yaml.

module "example_custom_manifests" {
  providers = {
    kustomization = kustomization.gke_gc0_europe-west1
  }

  source  = "kbst.xyz/catalog/custom-manifests/kustomization"
  version = "0.4.0"

  configuration = {
    apps = {
      namespace = "example-${terraform.workspace}"

      resources = [
        "${path.root}/manifests/example/upstream.yaml"
      ]

      common_labels = {
        "env" = terraform.workspace
      }
    }

    ops = {}
  }
}

Using the default configuration base key doesn't help.

module "example_custom_manifests" {
  providers = {
    kustomization = kustomization.gke_gc0_europe-west1
  }

  source  = "kbst.xyz/catalog/custom-manifests/kustomization"
  version = "0.4.0"

  configuration_base_key = "default" 
  configuration = {
    default = {
      apps = {
        resources = [
          "${path.root}/manifests/example/upstream.yaml"
        ]
      }

      ops = {}
    }
  }
}

However other examples from other documentation sources work fine. Note that I changed version 0.3.0 to 0.4.0 because otherwise I get an error in terraform

module "example_custom_manifests" {
  source  = "kbst.xyz/catalog/custom-manifests/kustomization"
  version = "0.4.0"

  configuration_base_key = "default"  # must match workspace name
  configuration = {
    default = {
      namespace = "example-${terraform.workspace}"

      resources = [
        "${path.root}/manifests/example/namespace.yaml",
        "${path.root}/manifests/example/deployment.yaml",
        "${path.root}/manifests/example/service.yaml"
      ]

      common_labels = {
        "env" = terraform.workspace
      }
    }
  }
}
pst commented 1 year ago

Thanks for reporting this. The version is indeed outdated and I should bump it in the docs.

The keys of the map need to match the name of your workspace. terraform workspace list

As for your second example, the default needs to replace apps and ops. Not wrap it. See below:

module "example_custom_manifests" {
  providers = {
    kustomization = kustomization.gke_gc0_europe-west1
  }

  source  = "kbst.xyz/catalog/custom-manifests/kustomization"
  version = "0.4.0"

  configuration_base_key = "default" 
  configuration = {
    default = {
      resources = [
        "${path.root}/manifests/example/upstream.yaml"
      ]
    }
  }
}