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

kubernetes_manifest CRD bootstraping #2334

Closed
singhbaljit opened this issue Oct 31, 2023 · 2 comments
Closed

kubernetes_manifest CRD bootstraping #2334

singhbaljit opened this issue Oct 31, 2023 · 2 comments
Labels

Comments

@singhbaljit
Copy link

When creating a CRD with kubernetes_manifest, there is an issue with terraform plan for the first time if the K8s operator is also applied with the same Terraform.

Terraform Version, Provider Version and Kubernetes Version

Terraform version: 1.5.7
Kubernetes provider version: 2.23.0
Kubernetes version: 1.24

Affected Resource(s)

kubernetes_manifest

Terraform Configuration Files

resource "helm_release" "operator" {
  name       = "emqx-operator"
  repository = "https://repos.emqx.io/charts"
  chart      = "emqx-operator"
}

resource "kubernetes_manifest" "broker" {
  depends_on = [helm_release.operator]

  manifest = yamldecode(<<-EOT

apiVersion: apps.emqx.io/v2beta1
kind: EMQX
...
EOT
  )
}

Panic Output

no matches for kind "EMQX" in group "apps.emqx.io"

Steps to Reproduce

  1. Define the operator and manifest for the CRD within the same Terraform
  2. Run terraform plan

Expected Behavior

Plan should not fail as this will work when terraform apply is called.

Actual Behavior

Error is thrown as its not able to recognize the CRD kind.

@singhbaljit singhbaljit changed the title kubernetes_manifest CRD boostraping kubernetes_manifest CRD bootstraping Oct 31, 2023
@BBBmau
Copy link
Contributor

BBBmau commented Nov 1, 2023

Hello, thank you for opening this issue @singhbaljit. What you've mentioned is a progressive apply issue where the solution is to do separate terraform applies instead of attempting to do a terraform apply that deals with multiple resources.

In this case you would want to run terraform apply for just the helm_release and then run a second terraform apply for the manifest

I've linked a part of the docs that mentions this here

@BBBmau BBBmau closed this as completed Nov 1, 2023
@txtmode
Copy link

txtmode commented Sep 26, 2024

Hello, thank you for opening this issue @singhbaljit. What you've mentioned is a progressive apply issue where the solution is to do separate terraform applies instead of attempting to do a terraform apply that deals with multiple resources.

In this case you would want to run terraform apply for just the helm_release and then run a second terraform apply for the manifest

I've linked a part of the docs that mentions this here

Alternatively use the provider kubectl for Kubernetes manifests: https://registry.terraform.io/providers/gavinbunney/kubectl/latest/docs/resources/kubectl_manifest
So you can apply in a single terraform apply and you can stop converting Kubernetes yaml resources to hcl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants