hashicorp / terraform-provider-consul

Terraform Consul provider
https://www.terraform.io/docs/providers/consul/
Mozilla Public License 2.0
124 stars 113 forks source link

[feature request] show minimal diff in the value when using consul_key_prefix #330

Open shantanugadgil opened 1 year ago

shantanugadgil commented 1 year ago

Terraform Version

1.3.7

Affected Resource(s)

Please list the resources as a list, for example:

Terraform Configuration Files

resource "consul_key_prefix" "myconfig" {
  path_prefix = "myconfig/something/"

  subkey {
    path = "charlie.yaml"
    value = file("${path.module}/charlie.yaml")
  }

  subkey {
    path = "alpha.json"
    value = file("${path.module}/alpha.json")
  }

  subkey {
    path = "bravo.yml"
    value = file("${path.module}/bravo.yml")
  }
}

Debug Output

N/A

Panic Output

N/A

Expected Behavior

When I change a single line in the YAML (or JSON) file which I PUT into Consul, I wish to see the diff of the changed content.

Actual Behavior

Currently the entire key is shown as "older removed" and "newer added".

Here, I have made a single line change in the file charlie.yaml

  # consul_key_prefix.myconfig  will be updated in-place
  ~ resource "consul_key_prefix" "myconfig" {
        id          = "myconfig/something/"
        # (3 unchanged attributes hidden)

      - subkey {
          - flags = 0 -> null
          - path  = "charlie.yaml" -> null
          - value = <<-EOT
                ---
                aaa: 'aaa'
                bbb: 'bbb'
            EOT -> null
        }
      + subkey {
          + flags = 0
          + path  = "charlie.yaml"
          + value = <<-EOT
                ---
                aaa: 'aaa'
            EOT
        }

Steps to Reproduce

Please list the steps required to reproduce the issue, for example: (use appropriate consul provider block)

Important Factoids

nothing special, should be reproducible using consul agent -dev

References

N/A

remilapeyre commented 11 months ago

Hello @shantanugadgil, I wanted to let you know that I have been trying to implement this and have mad esome experiments and I'm not sure it is possible to do this currently in Terraform. I will make more tests to understand what would need to be changed to have a better diff.

shantanugadgil commented 11 months ago

Hello @shantanugadgil, I wanted to let you know that I have been trying to implement this and have mad esome experiments and I'm not sure it is possible to do this currently in Terraform. I will make more tests to understand what would need to be changed to have a better diff.

This is good to know indeed!!!

shantanugadgil commented 7 months ago

hi @remilapeyre wondering if you were able to make any progress on this? if you have any test builds I can test it out

ameyabapat-bsft commented 2 months ago

Hello, Due to this long diff information, the overall diff is quite large, even if there are 1 or 2 lines changes in a few files.

When using Atlantis, we often face the GitHub API limit 403 API "secondary rate limit exceeded issue" in atlantis plan.

I believe there should be a function/logic to determine a minimal diff between two texts somewhere, it needs to be referred to or replicated in the consul repo. Can someone point me a similar logic in terraform or starting point towards solving this issue.?

I am willing to contribute to this one. @remilapeyre @skpratt