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

Custom hash function for router_nat.subnetwork #2379

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
1 change: 1 addition & 0 deletions products/compute/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides
is_set: true
subnetwork: !ruby/object:Overrides::Terraform::PropertyOverride
is_set: true
set_hash_func: computeRouterNatSubnetworkHash
subnetwork.sourceIpRangesToNat: !ruby/object:Overrides::Terraform::PropertyOverride
is_set: true
subnetwork.secondaryIpRangeNames: !ruby/object:Overrides::Terraform::PropertyOverride
Expand Down
26 changes: 26 additions & 0 deletions templates/terraform/constants/router_nat.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,29 @@ func resourceComputeRouterNatDrainNatIpsCustomDiff(diff *schema.ResourceDiff, me
}
return nil
}

func computeRouterNatSubnetworkHash(v interface{}) int {
obj := v.(map[string]interface{})
name := obj["name"]
sourceIpRanges := obj["source_ip_ranges_to_nat"]
sourceIpRangesHash := 0
if sourceIpRanges != nil {
sourceIpSet := sourceIpRanges.(*schema.Set)

for _, ipRange := range sourceIpSet.List() {
sourceIpRangesHash += schema.HashString(ipRange.(string))
}
}

secondaryIpRangeNames := obj["secondary_ip_range_names"]
secondaryIpRangeHash := 0
if secondaryIpRangeNames != nil {
secondaryIpRangeSet := secondaryIpRangeNames.(*schema.Set)

for _, secondaryIp := range secondaryIpRangeSet.List() {
secondaryIpRangeHash += schema.HashString(secondaryIp.(string))
}
}

return schema.HashString(NameFromSelfLinkStateFunc(name)) + sourceIpRangesHash + secondaryIpRangeHash
}
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ resource "google_compute_router_nat" "foobar" {
nat_ips = ["${google_compute_address.foobar.self_link}"]
source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS"
subnetwork {
name = "${google_compute_subnetwork.foobar.self_link}"
name = "${google_compute_subnetwork.foobar.name}"
source_ip_ranges_to_nat = ["ALL_IP_RANGES"]
}
}`, testId, testId, testId, testId, testId)
Expand Down