Home > Blockchain >  terraform helm release cannot re-use a name that is still in use
terraform helm release cannot re-use a name that is still in use

Time:11-16

I am trying to deploy an helm chart to a k8s cluster using terraform, it runs fine the first time, but when I try to update the chart I found myself with this error:

enter image description here

Error: cannot re-use a name that is still in use │ │ with helm_release.deliverable, │ on main.tf line 8, in resource "helm_release" "deliverable": │ 8: resource "helm_release" "deliverable" {

Now, if I delete the chart it will work fine ( the first run ), but I don't want to do that everytime, is there a way to reutilise the releasename?

here is my code:

resource "helm_release" "deliverable" {
  name                = "releaseapp"
  namespace           = "appnamespace"
  repository          = "https://myrepo/repository/helm/"
  chart               = "releaseapp"
  version             = "0.2.0"
  repository_username = "myuser"
  force_update        = true
  wait                = true
  repository_password = var.acrpass


  set {
    name  = "namespace"
    value = "appnamespace"
  }

  set {
    name  = "image.tag"
    value = var.applicationversion
  }

  set {
    name  = "image.tag"
    value = var.applicationversion
  }

  set {
    name  = "timestamp"
    value = local.timestamp_sanitized
  }
}

locals {
  timestamp                    = "${timestamp()}"
  timestamp_sanitized          = "${replace("${local.timestamp}", "/[- TZ:]/", "")}"
}

I tried to change the helm chart version I tried to add both

  force_update        = true
  wait                = true

but still no success. Would you be able to help me, please?

CodePudding user response:

Gitlab CI infrastructure terraform state wont accept special characters in its name, so no state were created. Therefore when trying to read from it, it failed and tries to create a new resource that already existed.

I had my state name create from the git branch that in the first case was feature/jira-task

changing from:

${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${CI_PROJECT_NAME}_${CI_COMMIT_BRANCH} 

TO:

${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${CI_PROJECT_NAME}_tfstate

Solved the problem.

  • Related