r/virutal_machine: Fix gateway discovery behavior #180
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current gateway discovery code makes an assumption that any device
tracked by VMware tools that is not virtual hardware on the instance
will be ordered after any devices that are (even though the device key
is properly being used as the source of truth when discovering
interfaces). It does this by using the device index in a specific
gateway entry as the literal index entry for the corresponding device in
the list of devices that have actually been counted for saving in
Terraform state. This will either point to the incorrect device or a
flat out out-of-bounds value, respectively causing incorrect diffs or
crashes.
This fixes the situation by searching for the actual device key in the
guest network information discovered by VMware tools - at the index
specified by the gateway entry, and then searching for that key in the
devices being counted for state. The index of the corresponding entry is
where the gateway is saved. If any of these searches come up dry, either
the gateway has legitimately moved and needs to be fixed or more than
likely was not defined in config.
Fixes #173.