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

consul: Fix several problems w/ consul_keys update #4787

Merged
merged 1 commit into from
Jan 27, 2016

Conversation

phinze
Copy link
Contributor

@phinze phinze commented Jan 21, 2016

Implementation notes:

  • The hash implementation was not considering key value, causing "diffs
    did not match" errors when a value was updated. Switching to default
    HashResource implementation fixes this
  • Using HashResource as a default exposed a bug in helper/schema that
    needed to be fixed so the Set function is picked up properly during
    Read
  • Stop writing back values into the key attribute; it triggers extra
    diffs when default is used. Computed values all just go into var.
  • Includes a state migration to prevent unnecessary diffs based on
    "key" attribute hashcodes changing.

In the tests:

  • Switch from leaning on the public demo Consul instance to requiring a
    CONSUL_HTTP_ADDR variable be set pointing to a consul agent -dev
    instance to be used only for testing.
  • Add a test that exposes the updating issues and covers the fixes

Fixes #774
Fixes #1866
Fixes #3023

@@ -277,7 +277,7 @@ func (w *MapFieldWriter) setSet(
// not the `value` directly is because this forces all types
// to become []interface{} (generic) instead of []string, which
// most hash functions are expecting.
s := &Set{F: schema.Set}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh my... this must've been lurking here since I did the refactoring that added schema.ZeroValue months ago. Sorry about that!

Curious to see if this will fix weird quirky behavior with other resources that use the default hash implementation. I know a few times I've seen "diffs don't match" errors that I then failed to reproduce, and it seems plausible that this would be the cause for at least some of them...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries! I think this may be the first TypeSet using the default implementation that gets written, since the behavior I saw was a nil reference panic, and we definitely would have noticed that elsewhere.

@apparentlymart
Copy link
Contributor

This LGTM!

Presumably changing the set hash function is going to cause Terraform to see all of the set items as changed, which will cause some extra diff noise but otherwise not do anything bad I think.

Not setting the value in the keys blocks also seems like a minor breaking change, but I can confirm that at least for my part I've never depended on that being set since it's always been more convenient to use var.whatever.

@phinze phinze force-pushed the phinze/fix-consul-keys-update branch from bb474a8 to ec6b3e1 Compare January 25, 2016 18:30
@phinze
Copy link
Contributor Author

phinze commented Jan 25, 2016

Thanks for the review, @apparentlymart! Did another pass on the code and ended up deciding to set back datacenter since it can be interpreted from the provider, so it can be used as a reference field.

Presumably changing the set hash function is going to cause Terraform to see all of the set items as changed, which will cause some extra diff noise but otherwise not do anything bad I think.

Good point. The proper thing to do here would be a state migration. I'll look into that.

Not setting the value in the keys blocks also seems like a minor breaking change

Yeah, I think you're right about it being a breaking change. The prior behavior was extra diffs when using default, though, so it's basically a fix. I'll call this out in the CHANGELOG when this gets merged so it's clear.

Implementation notes:

 * The hash implementation was not considering key value, causing "diffs
   did not match" errors when a value was updated. Switching to default
   HashResource implementation fixes this
 * Using HashResource as a default exposed a bug in helper/schema that
   needed to be fixed so the Set function is picked up properly during
   Read
 * Stop writing back values into the `key` attribute; it triggers extra
   diffs when `default` is used. Computed values all just go into `var`.
 * Includes a state migration to prevent unnecessary diffs based on
   "key" attribute hashcodes changing.

In the tests:

 * Switch from leaning on the public demo Consul instance to requiring a
   CONSUL_HTTP_ADDR variable be set pointing to a `consul agent -dev`
   instance to be used only for testing.
 * Add a test that exposes the updating issues and covers the fixes

Fixes #774
Fixes #1866
Fixes #3023
@phinze phinze force-pushed the phinze/fix-consul-keys-update branch from ec6b3e1 to 069425a Compare January 26, 2016 20:49
@phinze
Copy link
Contributor Author

phinze commented Jan 26, 2016

Okay I followed up with a state migration so the only BC-notable change is that "value" will no longer be updated.

@apparentlymart PTAL when you have the chance
@mitchellh would appreciate eyes on the state migration function - after floundering a bit trying to manually munge map[string]strings, i ended up using the field reader/writers which worked out pretty okay

@mitchellh
Copy link
Contributor

LGTM!

phinze added a commit that referenced this pull request Jan 27, 2016
consul: Fix several problems w/ consul_keys update
@phinze phinze merged commit 1cf84eb into master Jan 27, 2016
@phinze phinze deleted the phinze/fix-consul-keys-update branch January 27, 2016 20:03
@apparentlymart
Copy link
Contributor

Belated LGTM 😀

@ghost
Copy link

ghost commented Apr 28, 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 and limited conversation to collaborators Apr 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants