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

TypeSet is always be reordered #27018

Closed
3-commerce opened this issue Nov 24, 2020 · 2 comments
Closed

TypeSet is always be reordered #27018

3-commerce opened this issue Nov 24, 2020 · 2 comments
Labels
bug working as designed confirmed as reported and closed because the behavior is intended

Comments

@3-commerce
Copy link

3-commerce commented Nov 24, 2020

Terraform Version

Terraform v0.13.5
+ provider registry.terraform.io/hashicorp/google v3.48.0

Terraform Configuration Files

I add host_rule for hosts "beta.domain.tld"

resource "google_compute_url_map" "url_map_a" {
  project = "playground-public"
  name = "url-map-a"
  default_service = google_compute_backend_service.playground_a.id

  host_rule {
    hosts = ["sdwr.domain.tld"]
    path_matcher = "spaths"
  }

  host_rule {
    hosts = ["beta.domain.tld"]
    path_matcher = "bpaths"
  }

  path_matcher {
    name = "spaths"
    default_service = google_compute_backend_service.playground_sbs.id
  }

  path_matcher {
    name = "bpaths"
    default_service = google_compute_backend_service.playground_bbs.id
  }

Debug Output

- host_rule {
          - hosts        = [
              - "sdwr.domain.tld",
            ] -> null
          - path_matcher = "spaths" -> null
   }
+ host_rule {
          + hosts        = [
              + "beta.domain.tld",
            ]
          + path_matcher = "bpaths"
    }
 + host_rule {
          + hosts        = [
              + "sdwr.domain.tld",
            ]
          + path_matcher = "spaths"
    }

Expected Behavior

host_rule {
        hosts        = [
            "sdwr.domain.tld",
        ]
        path_matcher = "spaths"
}
+ host_rule {
          + hosts        = [
              + "beta.domain.tld",
            ]
          + path_matcher = "bpaths"
    }

Steps to Reproduce

Additional Context

TL;DR
Every part of new host_rule i add, the terraform will re-sort the host_rule order. It will make the terraform looks like removing existing host_rule and then add back the existing host_rule and the new host_rule in the same time.
I am affraid to use this in production, because i have 39 host_rule.
I cannot imagine if i add the 40th host_rule and terraform shows it removes 39 host_rule and then add 39 host_rule back + 1 new host_rule...
Magicly, when i apply it, the existing hosts aren't removed. So, it's like the terraform removes them only in terraform side but not in google cloud side
I have opened it in Google Cloud Provider
host_rule uses TypeSet and i think The TypeSet behaviour is on terraform site not provider site.

@3-commerce 3-commerce added bug new new issue not yet triaged labels Nov 24, 2020
@jbardin jbardin added working as designed confirmed as reported and closed because the behavior is intended and removed new new issue not yet triaged labels Nov 24, 2020
@jbardin
Copy link
Member

jbardin commented Nov 24, 2020

Hi @merceskoba

Yes, this can be an unfortunate behavior with this schema combination. In most cases terraform does not show changed elements within a set when constructing the diff output. What is happening is that there must be other "unimportant" change which are not shown here, causing these set elements to change their value. While we have heuristics to elide some lines of these trivial changes, it still causes the entire set value to change which needs to be displayed. The new output in 0.14 should at least present the changes in a sorted order to make them easier to spot.

The real culprit here is the legacy provider SDK, which cannot handle the full rich type system that is used within terraform. The impedance mismatch often leaks some changes, most often null values being replaced with empty values of the same type, and we work around those to the best of our abilities. There is currently work being done to develop a new SDK, which will have direct access to the same type system, giving providers more control of the data structures they store in the state.

Since this is primarily caused by the plugin SDK (though providers can sometimes work around it in their side), and there's not much more we can do in terraform core until a new SDK is in use, I'm going to close this out for now.

Thanks!

@ghost
Copy link

ghost commented Dec 25, 2020

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.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug working as designed confirmed as reported and closed because the behavior is intended
Projects
None yet
Development

No branches or pull requests

2 participants