Fix numeric indexes for tunnels and subnets #43
Merged
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.
This PR fixes compute route resource naming when tunnel_count is greater than 1.
Related issue:
Fixes #38.
To give more context what this PR is doing:
Originally, the module is trying to name and number the routes by tunnel number and subnet number, something like
gateway-route-1-2
, where1
here is the tunnel number and2
is the subnet number.To do so, it first computes the total number of routes (#tunnels * #subnets), and then tries to divvy that number up and number them, but it does this part incorrectly. In the old way, it was setting tunnel index to the index % # tunnels + 1, and subnet index to index % # subnets + 1, which if you have 2 tunnels and 2 subets, would lead to this result:
As you can see, you end up with duplicates. The correct way to go about this (which is what Jonathan is doing here), is to do effectively long division by some divisor (either # tunnels or # subnets), where the whole number is one part, and the remainder is the other part. So, in this code, he's choosing # subnets as the divisor, so, dividing by it for the tunnel index, and then modulo it for the subnet index. Doing this gives the intended behavior:
Another example:
We're always dividing by number of subnets, so if it's just 1, then 0 / 1 = 0 + 1 = 1, and for the 2nd one, 1 / 1 = 1 + 1 = 2, while anything modulo 1 will always be 0, +1 = 1