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

Helm resources are not recreated if the underlying cluster is destroyed #591

Closed
n-oden opened this issue Sep 21, 2020 · 9 comments
Closed

Comments

@n-oden
Copy link
Contributor

n-oden commented Sep 21, 2020

Terraform Version and Provider Version

$ terraform -v
Terraform v0.12.28
+ provider.google v3.39.0
+ provider.helm v1.3.0

$ helm version
version.BuildInfo{Version:"v3.3.3", GitCommit:"55e3ca022e40fe200fbc855938995f40b2a68ce0", GitTreeState:"dirty", GoVersion:"go1.15.2"}

Provider Version

  • 1.3.0

Affected Resource(s)

  • helm_release

Terraform Configuration Files

variable "project" {
  default = "my-test-project"
}

variable "region" {
  default = "us-east1"
}

provider "google" {
  region = var.region
}

resource "google_project_service" "container" {
  project = var.project
  service = "container.googleapis.com"

  disable_dependent_services = false
  disable_on_destroy         = false
}

resource "google_container_cluster" "default" {
  name               = "helm-test-cluster"
  location           = "${var.region}"
  initial_node_count = 1
  project            = var.project
  depends_on = [
    google_project_service.container
  ]

  master_auth {
    username = ""
    password = ""
    client_certificate_config {
      issue_client_certificate = false
    }
  }

  node_config {
    oauth_scopes = [
      "https://www.googleapis.com/auth/logging.write",
      "https://www.googleapis.com/auth/monitoring",
    ]
    metadata = {
      disable-legacy-endpoints = "true"
    }
  }

  timeouts {
    create = "30m"
    update = "40m"
  }
}

data "google_client_config" "provider" {}

provider "helm" {
  kubernetes {
    load_config_file       = false
    host                   = "https://${google_container_cluster.default.endpoint}"
    token                  = data.google_client_config.provider.access_token
    cluster_ca_certificate = base64decode(google_container_cluster.default.master_auth[0].cluster_ca_certificate)
  }
}

resource "helm_release" "redis" {
  name       = "redis"
  repository = "https://kubernetes-charts.storage.googleapis.com/"
  chart      = "redis"
  atomic     = true
  wait       = true
  namespace  = "default"
}

Debug Output

https://gist.github.com/n-oden/eb86c620c0c6c47866f2be2746491fe9

Expected Behavior

The Helm release should be re-created in the new cluster.

Actual Behavior

The old cluster is destroyed, the new cluster created in the new region, but the helm_release.redis resource is unchanged: terraform believes that it still exists, but of course it does not.

Steps to Reproduce

Create the cluster and the helm release, and then force re-creation of the cluster by changing the region variable:

  1. terraform apply -var region=us-east1
  2. `terraform apply -var region=us-central1

Important Factoids

I tested this running in Google Cloud Platform using GKE, but I suspect this is a more basic issue with the provider and the behavior would be the same against EKS etc.

References

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
@sebglon
Copy link
Contributor

sebglon commented Oct 8, 2020

For me it' the same root cause as here #593

I'd suggest setting an explicit dependency on the cluster resource in the helm_release resource, like this:

depends_on = [
  google_container_cluster.default,
]

@BunkerHarb
Copy link

For me it' the same root cause as here #593

I'd suggest setting an explicit dependency on the cluster resource in the helm_release resource, like this:

depends_on = [
  google_container_cluster.default,
]

i experience the same as n-oden (on azure) and adding a depends_on for the cluster doesn't fix it.

@n-oden
Copy link
Contributor Author

n-oden commented Dec 24, 2020

Belatedly @sebglon using depends_on does not address this issue: depends_on hard-codes ordering of resource creation, but does not imply anything about state relationships between resources. If resource B depends on resource A, terraform will wait until A is created before creating B, but deleting A does not delete B from state.

@justinas-b
Copy link

Yep, same issue here. If cluster is recreated or helm release is deleted directly on cluster, the helm_release stays in the state and terraform does not detect that the release itself is actually missing on k8s

@michelefa1988
Copy link

same issue here on azure. Are there any workarounds for this? Currently I remove the helm_release from the statefile manually, but I really hate doing this.

@n-oden
Copy link
Contributor Author

n-oden commented Sep 8, 2021

@michelefa1988 so far I haven't found any particularly good workarounds. You can potentially mitigate the issue by creating a random_id string, interpolating it into the name of all of your helm releases and setting its keepers field to something that will update when the cluster is rebuilt, but this invokes some pretty thorny dependency-ordering issues that you'll probalby have to manage by hand with depends_on and which will make cluster teardowns unnecessarily slow. Long story short I've built some local tooling that just manually deletes all of the resources out of tf state, and feel no better about it than you do. :)

@github-actions
Copy link

Marking this issue as stale due to inactivity. If this issue receives no comments in the next 30 days it will automatically be closed. If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. This helps our maintainers find and focus on the active issues. Maintainers may also remove the stale label at their discretion. Thank you!

Copy link

github-actions bot commented Dec 3, 2023

Marking this issue as stale due to inactivity. If this issue receives no comments in the next 30 days it will automatically be closed. If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. This helps our maintainers find and focus on the active issues. Maintainers may also remove the stale label at their discretion. Thank you!

@github-actions github-actions bot added the stale label Dec 3, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 3, 2024
@viceice
Copy link
Contributor

viceice commented Jan 3, 2024

pretty bad, still happening 😕

@github-actions github-actions bot removed the stale label Jan 3, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 3, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants