Diff values file using helm provider
Asked Answered
R

1

7

I hope you can help me light some more light on my issue.

Currently I'm using:

  • Terraform v1.3.5
  • Helm provider v2.8.0
  • Kubernetes provider v2.16.1

Lately I've been adapting the helm provider on Terraform, to help me manage Helm releases with more resiliency. It helps a lot to be able to plan changes and see what has changed and what remains the same. It merges really well with the infrastructure details and I can manage everything with just one tool, it has been great.

There is one thing that bothers me a little. It's the terraform plan preview of the values file, it just shows you that some changes have been made, but not where or which. Let me add an example.

File main.tf:

# I'm using the "manifest" setting to calculate manifest diffs
provider "helm" {
  kubernetes {
    config_path    = "~/.kube/config"
    config_context = "clusterconfig"
  }
  experiments {
    manifest = true
  }
}

# The helm chart lives locally on my repo. I'm passing the values file and an
#  override for the image tag.
resource "helm_release" "release" {
  name      = "example"
  chart     = "../../helm/chart"
  namespace = "example"
  wait      = true
  set {
    name  = "image.tag"
    value = "latest"
  }
  values = [
    file("helm/values-example.yaml")
  ]
}

This works great, the problem comes when I make a change on the values file. It shows the whole file instead of just the changes. For example in my values file I change the replicas from 1 to 2:

File values-example.yaml:

replicaCount: 1
image:
  repository: test
  pullPolicy: ifNotPresent

The execution:

$ terraform plan
(...)
Terraform will perform the following actions:

  # helm_release.example will be updated in-place
  ~ resource "helm_release" "example" {
      ~ manifest       = jsonencode(
          ~ {
              ~ "deployment.apps/apps/v1/deployname"      = {
                  ~ spec       = {
                      - replicas = 1 -> 2
                        }
                    }
                }
            }
        )
  ~ values                     = [
    - <<-EOT
    replicaCount: 1
    image:
      repository: test
      pullPolicy: ifNotPresent
    EOT,
    + <<-EOT
    replicaCount: 2
    image:
      repository: test
      pullPolicy: ifNotPresent
    EOT,
  ]

This makes it very difficult to see which values settings have been changed, when the values file is bigger.

So then, my question, do you know if there is a way to diff the values? I would like to see only the changes instead of the whole file.

What I've seen online:

Thanks in advance for the help. Let me know if I can help with any more information.

Rinee answered 5/1, 2023 at 12:10 Comment(1)
The exact same issue is in their repository here: github.com/hashicorp/terraform-provider-helm/issues/1121. Since it is not solved there, I suggest subscribing to the issue notifications for further updates.Folkmoot
C
1

I'm not sure how convenient it would be, but the alternative I see is to have basic stuff in the values.yaml file and for each property you need to update, to move it into a set block. Like this:

resource "helm_release" "release" {
  // ...
  values = [
    file("helm/values-example.yaml")
  ]
  set {
    name  = "replicaCount"
    value = "2"
  }
}

This approach will be also resilient to "order" changes that sometimes can happen in values file, I mean when a block of values is moved from top to bottom because it will look nicer.

Curtate answered 19/9, 2024 at 9:49 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.