Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to apply multiple crd resources from one file #2

Open
abdul90082 opened this issue Nov 24, 2022 · 2 comments
Open

Add a way to apply multiple crd resources from one file #2

abdul90082 opened this issue Nov 24, 2022 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@abdul90082
Copy link

Some charts include multiple crd resources in one file.
eg: https://raw.githubusercontent.com/Kong/charts/kong-2.13.1/charts/kong/crds/custom-resource-definitions.yaml

This seems to be not possible with your module.
What I did as a workaround:

variable "crds_urls" {
  type = list(object({
    count = string
    url   = string
  }))
  description = <<-EOF
  List of the URLs including the count of the crds per file 
  (due to terraform limitation)
  EOF
}

variable "server_side_apply" {
  type        = bool
  default     = false
  description = "Optional. Allow using server-side-apply method. Default false."
}
data "http" "yaml_file" {
  for_each = toset(var.crds_urls[*].url)
  url      = each.value

  lifecycle {
    postcondition {
      condition     = contains([200, 201, 204], self.status_code)
      error_message = "Status code invalid"
    }
  }
}

data "kubectl_file_documents" "crds" {
  for_each = toset(var.crds_urls[*].url)
  content  = data.http.yaml_file[each.value].response_body
}

locals {
  crds = flatten([
    for crd_url in var.crds_urls :
    data.kubectl_file_documents.crds[crd_url.url].documents
  ])
  crd_count = sum(var.crds_urls[*].count)
}

resource "kubectl_manifest" "crd" {
  count = local.crd_count

  # depends_on = [null_resource.status_check]
  yaml_body = local.crds[count.index]

  server_side_apply = var.server_side_apply
}

But this needs the count to be known before the apply so it's not perfect.
Any idea how to implement this?

@rpadovani
Copy link
Owner

Hi Abdul,
thanks for your patience on this.

Nothing simple comes to my mind, but it could be indeed an interesting feature. If somebody has any idea, please share it 😄

If I find a simple solution, I'll implement it.

@rpadovani rpadovani added enhancement New feature or request help wanted Extra attention is needed labels Dec 16, 2022
@BrianLovelace128
Copy link

Ran into this issue while using the module to install cert-manager crds. Threw for a bit of a loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants