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

fixed permadiff when subnet is optioanl #3780

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
3 changes: 3 additions & 0 deletions .changelog/5369.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
compute: fixed a permadiff on `subnetwork` when it is optional on `google_compute_network_endpoint_group`
```
10 changes: 10 additions & 0 deletions google-beta/common_diff_suppress.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,13 @@ func compareIpAddressOrSelfLinkOrResourceName(_, old, new string, _ *schema.Reso
func alwaysDiffSuppress(_, _, _ string, _ *schema.ResourceData) bool {
return true
}

// Use this method when subnet is optioanl and auto_create_subnetworks = true
// API sometimes choose a subnet so the diff needs to be ignored
func compareOptionalSubnet(_, old, new string, _ *schema.ResourceData) bool {
if isEmptyValue(reflect.ValueOf(new)) {
return true
}
// otherwise compare as self links
return compareSelfLinkOrResourceName("", old, new, nil)
}
2 changes: 1 addition & 1 deletion google-beta/resource_compute_network_endpoint_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ you create the resource.`,
Type: schema.TypeString,
Optional: true,
ForceNew: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
DiffSuppressFunc: compareOptionalSubnet,
Description: `Optional subnetwork to which all network endpoints in the NEG belong.`,
},
"zone": {
Expand Down
48 changes: 48 additions & 0 deletions google-beta/resource_compute_network_endpoint_group_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package google

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccComputeNetworkEndpointGroup_networkEndpointGroup(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": randString(t, 10),
}

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeNetworkEndpointGroupDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeNetworkEndpointGroup_networkEndpointGroup(context),
},
{
ResourceName: "google_compute_network_endpoint_group.neg",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"network", "subnetwork", "zone"},
},
},
})
}

func testAccComputeNetworkEndpointGroup_networkEndpointGroup(context map[string]interface{}) string {
return Nprintf(`
resource "google_compute_network_endpoint_group" "neg" {
name = "tf-test-my-lb-neg%{random_suffix}"
network = google_compute_network.default.id
default_port = "90"
zone = "us-central1-a"
}

resource "google_compute_network" "default" {
name = "tf-test-neg-network%{random_suffix}"
auto_create_subnetworks = true
}
`, context)
}
2 changes: 1 addition & 1 deletion google-beta/resource_gke_hub_feature_membership_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"testing"

dcl "github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl"
"github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl"
gkehub "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/gkehub/beta"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
Expand Down