Skip to content

Commit 10ef26a

Browse files
committed
actually fix container_network_policy diff suppress and add test
1 parent 5f3070e commit 10ef26a

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

google/resource_container_cluster.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -303,14 +303,14 @@ func resourceContainerCluster() *schema.Resource {
303303
Default: false,
304304
},
305305
"provider": {
306-
Type: schema.TypeString,
307-
Default: "PROVIDER_UNSPECIFIED",
308-
Optional: true,
309-
ValidateFunc: validation.StringInSlice([]string{"PROVIDER_UNSPECIFIED", "CALICO"}, false),
306+
Type: schema.TypeString,
307+
Default: "PROVIDER_UNSPECIFIED",
308+
Optional: true,
309+
ValidateFunc: validation.StringInSlice([]string{"PROVIDER_UNSPECIFIED", "CALICO"}, false),
310+
DiffSuppressFunc: emptyOrDefaultStringSuppress("PROVIDER_UNSPECIFIED"),
310311
},
311312
},
312313
},
313-
DiffSuppressFunc: emptyOrDefaultStringSuppress("PROVIDER_UNSPECIFIED"),
314314
},
315315

316316
"node_config": schemaNodeConfig,

google/resource_container_cluster_test.go

+27-1
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ import (
2020
func TestAccContainerCluster_basic(t *testing.T) {
2121
t.Parallel()
2222

23+
clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
2324
resource.Test(t, resource.TestCase{
2425
PreCheck: func() { testAccPreCheck(t) },
2526
Providers: testAccProviders,
2627
CheckDestroy: testAccCheckContainerClusterDestroy,
2728
Steps: []resource.TestStep{
2829
{
29-
Config: testAccContainerCluster_basic(fmt.Sprintf("cluster-test-%s", acctest.RandString(10))),
30+
Config: testAccContainerCluster_basic(clusterName),
3031
Check: resource.ComposeTestCheckFunc(
3132
testAccCheckContainerCluster(
3233
"google_container_cluster.primary"),
@@ -135,6 +136,20 @@ func TestAccContainerCluster_withNetworkPolicyEnabled(t *testing.T) {
135136
"network_policy"),
136137
),
137138
},
139+
{
140+
Config: testAccContainerCluster_withNetworkPolicyDisabled(clusterName),
141+
Check: resource.ComposeTestCheckFunc(
142+
testAccCheckContainerCluster(
143+
"google_container_cluster.with_network_policy_enabled"),
144+
resource.TestCheckResourceAttr("google_container_cluster.with_network_policy_enabled",
145+
"network_policy.0.enabled", "false"),
146+
),
147+
},
148+
{
149+
Config: testAccContainerCluster_withNetworkPolicyDisabled(clusterName),
150+
PlanOnly: true,
151+
ExpectNonEmptyPlan: false,
152+
},
138153
},
139154
})
140155
}
@@ -1085,6 +1100,17 @@ resource "google_container_cluster" "with_network_policy_enabled" {
10851100
}`, clusterName)
10861101
}
10871102

1103+
func testAccContainerCluster_withNetworkPolicyDisabled(clusterName string) string {
1104+
return fmt.Sprintf(`
1105+
resource "google_container_cluster" "with_network_policy_enabled" {
1106+
name = "%s"
1107+
zone = "us-central1-a"
1108+
initial_node_count = 1
1109+
1110+
network_policy = {}
1111+
}`, clusterName)
1112+
}
1113+
10881114
func testAccContainerCluster_withMasterAuthorizedNetworksConfig(clusterName string, cidrs []string) string {
10891115

10901116
cidrBlocks := ""

0 commit comments

Comments
 (0)