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

Larger diff than expected generated when changing helm_release 'set' 'value' #915

Closed
adcharre opened this issue Jul 11, 2022 · 3 comments
Closed
Labels

Comments

@adcharre
Copy link
Contributor

Terraform, Provider, Kubernetes and Helm Versions

Terraform version: v1.2.4
Provider version: v2.6.0
Kubernetes version: v1.23.6
Helm version: version.BuildInfo{Version:"v3.9.0", GitCommit:"7ceeda6c585217a19a1131663d8cd1f7d641b2a7", GitTreeState:"clean", GoVersion:"go1.17.5"}

Affected Resource(s)

  • helm_release

Terraform Configuration Files

terraform {
  required_version = ">= 1.0.0"
  required_providers {
    kubernetes = {
      source  = "hashicorp/kubernetes"
      version = ">= 2.8.0"
    }
    helm = {
      source  = "hashicorp/helm"
      version = ">= 2.4.1"
    }
  }
}

provider "kubernetes" {
  config_path = "~/.kube/config"
}

provider "helm" {
  kubernetes {
    config_path = "~/.kube/config"
  }
}

variable "memory" {
  type = string
}

resource "helm_release" "test" {
    name = "test"
    repository = "https://coredns.github.io/helm"
    chart = "coredns"

    set {
      name = "replicaCount"
      value = "1"
    }

    set {
      name = "resources.requests.memory"
      value = var.memory
    }
}

Debug Output

NOTE: In addition to Terraform debugging, please set HELM_DEBUG=1 to enable debugging info from helm.

Terraform log and state file: https://gist.github.com/adcharre/120482e9f4d4bcb5641c49f6fb35f0f1

Panic Output

Steps to Reproduce

  1. terraform apply -auto-approve -var memory=100Mi
  2. terraform apply -auto-approve -var memory=120Mi
  3. terraform apply -auto-approve -var memory=100Mi

Expected Behavior

On second and third apply, xxx and yyy would be a number.

helm_release.test: Refreshing state... [id=test]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # helm_release.test will be updated in-place
  ~ resource "helm_release" "test" {
        id                         = "test"
        name                       = "test"
        # (28 unchanged attributes hidden)

      - set {
          - name  = "resources.requests.memory" -> null
          - value = "xxxMi" -> null
        }
      + set {
          + name  = "resources.requests.memory"
          + value = "yyyMi"
        }
    }

Plan: 0 to add, 1 to change, 0 to destroy.
helm_release.test: Modifying... [id=test]
helm_release.test: Modifications complete after 1s [id=test]

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

Actual Behavior

On second and third apply:

helm_release.test: Refreshing state... [id=test]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # helm_release.test will be updated in-place
  ~ resource "helm_release" "test" {
        id                         = "test"
        name                       = "test"
        # (27 unchanged attributes hidden)

      - set {
          - name  = "replicaCount" -> null
          - value = "1" -> null
        }
      + set {
          + name  = "replicaCount"
          + value = "1"
        }
      - set {
          - name  = "resources.requests.memory" -> null
          - value = "xxxMi" -> null
        }
      + set {
          + name  = "resources.requests.memory"
          + value = "yyyMi"
        }
    }

Plan: 0 to add, 1 to change, 0 to destroy.
helm_release.test: Modifying... [id=test]
helm_release.test: Modifications complete after 1s [id=test]

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

On the third apply the follow warning is also seen in the log:

2022-07-11T12:02:27.741+0100 [WARN]  Provider "registry.terraform.io/hashicorp/helm" produced an unexpected new value for helm_release.test during refresh.
      - .set: planned set element cty.ObjectVal(map[string]cty.Value{"name":cty.StringVal("replicaCount"), "type":cty.NullVal(cty.String), "value":cty.StringVal("1")}) does not correlate with any element in actual

This looks like it might therefore be related to #711
Examining the state file it is clear that the "type" value for the "replicaCount" is now set to null.

Important Factoids

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
@adcharre adcharre added the bug label Jul 11, 2022
adcharre added a commit to adcharre/terraform-provider-helm that referenced this issue Jul 11, 2022
Fix issue hashicorp#915 where when re-deploying a helm_release after changing a 'set' 'value' the plan generated indicates that values not changing will be deleted and re-applied even though they have not been changed.

The issue is caused by the resource diff process removing the 'set' 'type' value from the state as it was not set in the original terraform code. When initially applying the plan the default value "" was used for the 'set' 'type' and stored in the state, when redeploying the original value of 'set' 'type' is requested  but as no default has been set in the schema it is marked as removed, which then results in null being stored in the state for the value of 'set' 'type'.
This cause an internal warning to be generated in the logs:
"Provider "registry.terraform.io/hashicorp/helm" produced an unexpected new value for helm_release.test during refresh."
@peay
Copy link

peay commented Aug 18, 2022

I am also hitting this. I would argue that the expected behaviour should be

      ~ set {
           name  = "resources.requests.memory"
          ~ value = "xxxMi" -> "yyyMi"
        }

instead of still having a deletion and an addition for that changed value (i.e., when a single value is updated, I believe it should show as "update in-place")

edit: this issue might be a duplicate of #627 and #749

@iBrandyJackson
Copy link
Member

Closing this issue as resolved with https://github.com/hashicorp/terraform-provider-helm/releases/tag/v2.8.0 - in PR #916

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants