Terraform-provider-helm: Terraform state is updated even if apply fails

Created on 29 Jul 2020  路  5Comments  路  Source: hashicorp/terraform-provider-helm

Terraform Version and Provider Version


Terraform v0.12.24

Provider Version

provider.helm v1.2.3

Affected Resource(s)

  • helm_release

Expected Behavior


Terraform state is retained as it is if helm fails to update the release.

Actual Behavior


Terraform state is updated and hence running plan once again shows everything as up to date.

Steps to Reproduce

  1. terraform apply
  2. Delete a required chart from the local folder
  3. Make some changes to values and apply again
  4. Apply would fail with error found in Chart.yaml, but missing in charts/ directory:
  5. Run terraform plan again. Everything would be up to date.

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
bug

Most helpful comment

I'm facing the same issue! I created a trace that show's this problem happening (you can check each individual command by searching for the string pedgonca @ N103303 in /tmp/test_terraform).

A full test can be done like this:

Create a local k8s cluster - I used kind

$ kind create cluster
$ kind get kubeconfig > kind.yaml

Initial terraform config

main.tf

resource "helm_release" "mysqldb" {
  name  = "mysqldb"
  chart = "stable/mysql"
}

providers.tf

provider "helm" {
  version = "~> 1.2.2"
  kubernetes {
    config_path = "/tmp/test_terraform/kind.yaml"
  }
}

Replicate the issue

# pedgonca @ N103303 in /tmp/test_terraform [21:46:32] 
$ terraform apply

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # helm_release.mysqldb will be created
  + resource "helm_release" "mysqldb" {
      + atomic                     = false
      + chart                      = "stable/mysql"
      + cleanup_on_fail            = false
      + create_namespace           = false
      + dependency_update          = false
      + disable_crd_hooks          = false
      + disable_openapi_validation = false
      + disable_webhooks           = false
      + force_update               = false
      + id                         = (known after apply)
      + lint                       = false
      + max_history                = 0
      + metadata                   = (known after apply)
      + name                       = "mysqldb"
      + namespace                  = "default"
      + recreate_pods              = false
      + render_subchart_notes      = true
      + replace                    = false
      + reset_values               = false
      + reuse_values               = false
      + skip_crds                  = false
      + status                     = "deployed"
      + timeout                    = 300
      + verify                     = false
      + version                    = "1.6.6"
      + wait                       = true
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

helm_release.mysqldb: Creating...
helm_release.mysqldb: Still creating... [10s elapsed]
helm_release.mysqldb: Creation complete after 14s [id=mysqldb]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

# pedgonca @ N103303 in /tmp/test_terraform [21:47:06] 
$ sed -i.bak 's#stable/mysql#stable/FOOBARmysql#' main.tf

# pedgonca @ N103303 in /tmp/test_terraform [21:47:29] 
$ terraform apply                                        
helm_release.mysqldb: Refreshing state... [id=mysqldb]

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # helm_release.mysqldb will be updated in-place
  ~ resource "helm_release" "mysqldb" {
        atomic                     = false
      ~ chart                      = "stable/mysql" -> "stable/FOOBARmysql"
        cleanup_on_fail            = false
        create_namespace           = false
        dependency_update          = false
        disable_crd_hooks          = false
        disable_openapi_validation = false
        disable_webhooks           = false
        force_update               = false
        id                         = "mysqldb"
        lint                       = false
        max_history                = 0
        metadata                   = [
            {
                chart     = "mysql"
                name      = "mysqldb"
                namespace = "default"
                revision  = 1
                values    = "null"
                version   = "1.6.6"
            },
        ]
        name                       = "mysqldb"
        namespace                  = "default"
        recreate_pods              = false
        render_subchart_notes      = true
        replace                    = false
        reset_values               = false
        reuse_values               = false
        skip_crds                  = false
        status                     = "deployed"
        timeout                    = 300
        verify                     = false
        version                    = "1.6.6"
        wait                       = true
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

helm_release.mysqldb: Modifying... [id=mysqldb]

Error: failed to download "stable/FOOBARmysql" (hint: running `helm repo update` may help)

  on main.tf line 1, in resource "helm_release" "mysqldb":
   1: resource "helm_release" "mysqldb" {



# pedgonca @ N103303 in /tmp/test_terraform [21:47:41] C:1
$ terraform apply                                        
helm_release.mysqldb: Refreshing state... [id=mysqldb]

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

# pedgonca @ N103303 in /tmp/test_terraform [21:47:53] 

Summary

As seen in the above execution, a failed terrraform apply in for an helm chart, will still save the state of the helm chart has updated, even tho the apply failed - when running the apply a second time, it just says the state is up to date.

All 5 comments

@kishorv06 could you provide a trace of the two apply sequences so we can take a deeper look into this?
https://www.terraform.io/docs/internals/debugging.html

I'm facing the same issue! I created a trace that show's this problem happening (you can check each individual command by searching for the string pedgonca @ N103303 in /tmp/test_terraform).

A full test can be done like this:

Create a local k8s cluster - I used kind

$ kind create cluster
$ kind get kubeconfig > kind.yaml

Initial terraform config

main.tf

resource "helm_release" "mysqldb" {
  name  = "mysqldb"
  chart = "stable/mysql"
}

providers.tf

provider "helm" {
  version = "~> 1.2.2"
  kubernetes {
    config_path = "/tmp/test_terraform/kind.yaml"
  }
}

Replicate the issue

# pedgonca @ N103303 in /tmp/test_terraform [21:46:32] 
$ terraform apply

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # helm_release.mysqldb will be created
  + resource "helm_release" "mysqldb" {
      + atomic                     = false
      + chart                      = "stable/mysql"
      + cleanup_on_fail            = false
      + create_namespace           = false
      + dependency_update          = false
      + disable_crd_hooks          = false
      + disable_openapi_validation = false
      + disable_webhooks           = false
      + force_update               = false
      + id                         = (known after apply)
      + lint                       = false
      + max_history                = 0
      + metadata                   = (known after apply)
      + name                       = "mysqldb"
      + namespace                  = "default"
      + recreate_pods              = false
      + render_subchart_notes      = true
      + replace                    = false
      + reset_values               = false
      + reuse_values               = false
      + skip_crds                  = false
      + status                     = "deployed"
      + timeout                    = 300
      + verify                     = false
      + version                    = "1.6.6"
      + wait                       = true
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

helm_release.mysqldb: Creating...
helm_release.mysqldb: Still creating... [10s elapsed]
helm_release.mysqldb: Creation complete after 14s [id=mysqldb]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

# pedgonca @ N103303 in /tmp/test_terraform [21:47:06] 
$ sed -i.bak 's#stable/mysql#stable/FOOBARmysql#' main.tf

# pedgonca @ N103303 in /tmp/test_terraform [21:47:29] 
$ terraform apply                                        
helm_release.mysqldb: Refreshing state... [id=mysqldb]

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # helm_release.mysqldb will be updated in-place
  ~ resource "helm_release" "mysqldb" {
        atomic                     = false
      ~ chart                      = "stable/mysql" -> "stable/FOOBARmysql"
        cleanup_on_fail            = false
        create_namespace           = false
        dependency_update          = false
        disable_crd_hooks          = false
        disable_openapi_validation = false
        disable_webhooks           = false
        force_update               = false
        id                         = "mysqldb"
        lint                       = false
        max_history                = 0
        metadata                   = [
            {
                chart     = "mysql"
                name      = "mysqldb"
                namespace = "default"
                revision  = 1
                values    = "null"
                version   = "1.6.6"
            },
        ]
        name                       = "mysqldb"
        namespace                  = "default"
        recreate_pods              = false
        render_subchart_notes      = true
        replace                    = false
        reset_values               = false
        reuse_values               = false
        skip_crds                  = false
        status                     = "deployed"
        timeout                    = 300
        verify                     = false
        version                    = "1.6.6"
        wait                       = true
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

helm_release.mysqldb: Modifying... [id=mysqldb]

Error: failed to download "stable/FOOBARmysql" (hint: running `helm repo update` may help)

  on main.tf line 1, in resource "helm_release" "mysqldb":
   1: resource "helm_release" "mysqldb" {



# pedgonca @ N103303 in /tmp/test_terraform [21:47:41] C:1
$ terraform apply                                        
helm_release.mysqldb: Refreshing state... [id=mysqldb]

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

# pedgonca @ N103303 in /tmp/test_terraform [21:47:53] 

Summary

As seen in the above execution, a failed terrraform apply in for an helm chart, will still save the state of the helm chart has updated, even tho the apply failed - when running the apply a second time, it just says the state is up to date.

@mcuadros any word on either of these two options proposed in these PRs?

Is this a duplicate of #472?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aaronmell picture aaronmell  路  22Comments

dangarthwaite picture dangarthwaite  路  19Comments

alexkreidler picture alexkreidler  路  71Comments

stefanthorpe picture stefanthorpe  路  14Comments

iliasbertsimas picture iliasbertsimas  路  12Comments