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

core: refactoring the way sets work internally v2 #663

Merged
merged 1 commit into from
Dec 15, 2014
Merged

core: refactoring the way sets work internally v2 #663

merged 1 commit into from
Dec 15, 2014

Conversation

svanharmelen
Copy link
Contributor

This is a refactored solution for PR #616. Functionally this is still the same change, but it’s implemented a lot cleaner with less code and less changes to existing parts of TF.

This is a refactored solution for PR #616. Functionally this is still
the same change, but it’s implemented a lot cleaner with less code and
less changes to existing parts of TF.
@svanharmelen
Copy link
Contributor Author

@armon @mitchellh please share any comments/feedback on this refactored solution so we can work towards getting this merged.

Thx...

@armon
Copy link
Member

armon commented Dec 15, 2014

Could you please explain at a higher level what this is doing conceptually? I'm having a hard time piecing it together just from the code.

@svanharmelen
Copy link
Contributor Author

Yeah, I can imagine as I too needed some time to get my head around all the nitty gritty details of what is going on and what depends on what...

Very high level this PR changes how sets are handled internally by changing the internal representation from a list to a map.

Until now a set was handled as a list (even though the actual implementation was already using a map), so all items were sorted based on their calculated hashes and then received an 'item number' based on a zero-based index.

After applying this PR sets are handled as maps where the key is the calculated hash and the value is the the actual item. So by that the 'item number' used to find and/or access an item changed from something that depended on the hashes of the other items in the same set (which determined the order and so the given 'item number'), to a deterministic number related to that specific item.

An example of something this fixes could be seen here and here. These (currently commented out) tests fail without this PR. They are now uncommented in this PR as they work as expected (at least how I would expect it 😉) after adding this PR.

Next to this primary change I needed to add some additional logic that made sure diffing the diffs (as called here during a terraform apply run) didn't fail. During the initial hash calculation for items coming from your config, there can be values that still need to be interpolated, but can only be interpolated once the terraform apply command is already running and the referenced resources are created.

So once the variables get interpolated into their actual values, the hash will also change (depending on you given set func of course). To fix this TF will now check if the set item has any values that still need to be interpolated, and if so it will calculate an approximate hash based on the values available at that time. These approximate hashes are shown on screen as something like ~56458795, so with a tilde in front of it which tells both the user as the Same func that this value will most likely change during the terraform apply fase, preventing it to fail on the updated hashes.

Does this help clarifying this PR? If not please let me know any specific question you still have. Or if that are too many question or if things still just are not clear enough, then maybe we should do a Skype or Google Hangout to go through the PR?

@@ -113,6 +113,25 @@ func (d *ResourceData) HasChange(key string) bool {
return !reflect.DeepEqual(o, n)
}

// hasComputedSubKeys walks true a schema and returns whether or not the
Copy link
Contributor

Choose a reason for hiding this comment

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

typo, not a big deal, but "walks true"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoeps! Will fix as soon as any other comments are in... Thx...

@mitchellh
Copy link
Contributor

This looks great! I'm going to go ahead and merge, I commented on a coupe things, though.

@mitchellh
Copy link
Contributor

I'm glad you were able to get rid of the modification to ResourceProvider, that was the main cognitive blocker earlier.

mitchellh added a commit that referenced this pull request Dec 15, 2014
core: refactoring the way sets work internally v2
@mitchellh mitchellh merged commit 6a66379 into hashicorp:master Dec 15, 2014
@svanharmelen
Copy link
Contributor Author

Nice! Already commented on your reviews and will update them right away so this topic can be closed...

@mitchellh
Copy link
Contributor

Thanks. :)

@mitchellh
Copy link
Contributor

Feel free to commit those changes directly as they're all pretty minor.

@svanharmelen svanharmelen deleted the f-fix/change-set-logic branch December 15, 2014 22:12
phinze added a commit to phinze/terraform that referenced this pull request Jan 10, 2015
- 5.6.17 is no longer a valid mysql engine version, bumping to 5.6.21
- updating security_group_names assertion to match new set structure
  introduce in hashicorp#663
@ghost
Copy link

ghost commented May 4, 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 May 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants