terraform-provider-helm icon indicating copy to clipboard operation
terraform-provider-helm copied to clipboard

Make values diffs more useful, possibly by accepting maps.

Open Patricol opened this issue 4 years ago • 12 comments

Description

When applying changes to helm_releases that use values, the diff output reports only that the entire values parameter has been removed and re-added; not marking the specific pieces that changed.

This becomes very problematic when using large values values.

Jenkins configured with JCasC is an example where it's reasonable to have a few hundred lines in values; and adding job-dsls can quickly get out of hand; as lengthy scripts are reformatted/escaped and inserted into values.

In my use case, changing a single line causes the terraform plan to spit out a 2748 line diff.

In these and all other usecases, I set values to a list of a single yamlencoded map.

Afaik it would be pretty trivial to extract a very concise diff using those maps.

If we just had a values_maps parameter in helm_release that would accept list(map) and yamlencode those maps before appending them to the values list, then handling the values list the same way it currently is; that seems like it would solve the issue with almost no effort for either the implementer or user.

I'd be happy to open a PR for this if it is a welcome change.

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

Patricol avatar Feb 23 '21 23:02 Patricol

Actually I think values_maps would be better as values_map; a single map.

Users can trivially merge the maps themselves, and the diffs will be even more concise and meaningful.

Patricol avatar Feb 24 '21 00:02 Patricol

This appears to be blocked by relatively fundamental limitations on Terraform's handling of maps with mixed types.

Patricol avatar Feb 24 '21 02:02 Patricol

We encounter the same problem our configurations are really large already so change is not visible in the plan, would be a great feature/improvement. For me it does not sound to complicated, but it should not mix up with the current string values because the ordering is no longer clear then.

tyriis avatar Mar 08 '21 10:03 tyriis

Was this attempted before? I'm kind of surprised this was only just opened. Seems like fairly fundamental feature for any helm_release resource with a non-trivial about of values right?

red8888 avatar Mar 09 '21 19:03 red8888

Is there an example that terraform's limitation block this feature?

fancl20 avatar Jul 29 '21 13:07 fancl20

Hey folks, just writing in support of this change. It would be great if the diffs were more meaningful, as the long log outputs in a change to values.yaml make it really hard to read when debugging.

noahsbwilliams avatar Dec 13 '21 18:12 noahsbwilliams

I'm having the same issue and have been experimenting with the following:

I have the following resource:

resource "null_resource" "show_diff" {
  triggers = {
    a = <<-EOT
    line 1
    line 2
    line 3
    EOT
    b = <<-EOT
    line A
    line B
    EOT
  }
}

I make the initial apply and then make the following changes:

resource "null_resource" "show_diff" {
  triggers = {
    a = <<-EOT
    line 1
    line 2 updated
    line 4 added
    EOT
    b = <<-EOT
    line A
    line C added
    EOT
  }
}

Doing the plan on the latter shows the following:

  # null_resource.show_diff must be replaced
-/+ resource "null_resource" "show_diff" {
      ~ id       = "4315918890606661203" -> (known after apply)
      ~ triggers = { # forces replacement
          ~ "a" = <<-EOT
                line 1
              - line 2
              - line 3
              + line 2 updated
              + line 4 added
            EOT
          ~ "b" = <<-EOT
                line A
              - line B
              + line C added
            EOT
        }
    }

The resource gets replaced but that's specificity of null_resource.

However the diff seems to show things correctly.

So I'm wondering... Currently the values has type list(string). What if it had type map(string) where the keys determine the order (as list is ordered and map is not). The resource would be able to easily rebuild the list from the map using the keys as order and corresponding values as list elements.

Rebuilding the list from map would be equivalent to Terraform functions:

values_as_list = [ for k in sort(keys(var.values)) : var.values[k] ]

slawekzachcial avatar Sep 16 '22 20:09 slawekzachcial

Building upon my previous comment, a workaround to show a diff of values could be the use of null_resource.

locals {
  values = templatefile("values.yaml", {
    a = "b",
    c = "d",
    ...
  })
}

resource "null_resource" "helm_release_values" {
  triggers = {
    values = local.values
  }
}

resource "helm_release" "this" {
  ...
  values = [local.values]
}

Every time the value of the local values changes, Terraform would show a difference for the null_resource triggers.

The only drawback is that null_resource will get recreated each time the values change, which may generate some mental overhead, especially in larger projects.

slawekzachcial avatar Sep 17 '22 08:09 slawekzachcial

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[bot] avatar Sep 18 '23 00:09 github-actions[bot]

One additional possibility would be to accept a values_hcl where the conversion is only done at the level of the provider internals... This would prob allow diffs to run as smoothly as they run on other parts of terraform...

joaocc avatar Sep 27 '23 22:09 joaocc