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

Suppress private_endpoint_subnetwork when master_ipv4_cidr_block is set #10101

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
Original file line number Diff line number Diff line change
Expand Up @@ -1684,7 +1684,7 @@ func ResourceContainerCluster() *schema.Resource {
Optional: true,
ForceNew: true,
AtLeastOneOf: privateClusterConfigKeys,
DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName,
DiffSuppressFunc: containerClusterPrivateClusterConfigSuppress,
Description: `Subnetwork in cluster's network where master's endpoint will be provisioned.`,
},
"public_endpoint": {
Expand Down Expand Up @@ -6387,6 +6387,14 @@ func containerClusterPrivateClusterConfigSuppress(k, old, new string, d *schema.
return suppressNodes && !hasSubnet
} else if k == "private_cluster_config.#" {
return suppressEndpoint && suppressNodes && !hasSubnet && !hasGlobalAccessConfig
} else if k == "private_cluster_config.0.private_endpoint_subnetwork" {
// Before regular compare, for the sake of private flexible cluster,
// suppress diffs in private_endpoint_subnetwork when
// master_ipv4_cidr_block is set
// && private_endpoint_subnetwork is unset in terraform (new value == "")
// && private_endpoint_subnetwork is returned from resource (old value != "")
_, hasMasterCidr := d.GetOk("private_cluster_config.0.master_ipv4_cidr_block")
return (hasMasterCidr && new == "" && old != "") || tpgresource.CompareSelfLinkOrResourceName(k, old, new, d)
}
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5643,6 +5643,62 @@ resource "google_container_cluster" "with_private_endpoint_subnetwork" {
`, containerNetName, clusterName)
}

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

clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
containerNetName := fmt.Sprintf("tf-test-container-net-%s", acctest.RandString(t, 10))

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccContainerCluster_withCidrBlockWithoutPrivateEndpointSubnetwork(containerNetName, clusterName, "us-central1-a"),
},
{
ResourceName: "google_container_cluster.with_private_flexible_cluster",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"min_master_version", "deletion_protection"},
},
},
})
}

func testAccContainerCluster_withCidrBlockWithoutPrivateEndpointSubnetwork(containerNetName, clusterName, location string) string {
return fmt.Sprintf(`
resource "google_compute_network" "container_network" {
name = "%s"
auto_create_subnetworks = false
}

resource "google_compute_subnetwork" "container_subnetwork" {
name = google_compute_network.container_network.name
network = google_compute_network.container_network.name
ip_cidr_range = "10.0.36.0/24"
}

resource "google_container_cluster" "with_private_flexible_cluster" {
name = "%s"
location = "%s"
min_master_version = "1.29"
initial_node_count = 1

networking_mode = "VPC_NATIVE"
network = google_compute_network.container_network.name
subnetwork = google_compute_subnetwork.container_subnetwork.name

private_cluster_config {
enable_private_nodes = true
master_ipv4_cidr_block = "10.42.0.0/28"
}
deletion_protection = false
}
`, containerNetName, clusterName, location)
}

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

Expand Down