Skip to content
Open
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 @@ -18,6 +18,9 @@ func DataSourceGoogleContainerCluster() *schema.Resource {

// Set 'Optional' schema elements
tpgresource.AddOptionalFieldsToSchema(dsSchema, "project", "location")
// skip_node_pool_refresh is an input to the read path (flattenClusterNodePools),
// so it must be settable instead of computed-only. See resource_container_cluster.go.
tpgresource.AddOptionalFieldsToSchema(dsSchema, "skip_node_pool_refresh")

return &schema.Resource{
Read: datasourceContainerClusterRead,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,26 @@ func TestAccContainerClusterDatasource_regional(t *testing.T) {
})
}

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

networkName := tpgcompute.BootstrapSharedTestNetwork(t, "gke-cluster")
subnetworkName := tpgcompute.BootstrapSubnet(t, "gke-cluster", networkName)

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
Steps: []resource.TestStep{
{
Config: testAccContainerClusterDatasource_skipNodePoolRefresh(acctest.RandString(t, 10), networkName, subnetworkName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.google_container_cluster.kubes", "node_pool.#", "0"),
),
},
},
})
}

func testAccContainerClusterDatasource_zonal(suffix, networkName, subnetworkName string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "kubes" {
Expand All @@ -81,6 +101,28 @@ data "google_container_cluster" "kubes" {
`, suffix, networkName, subnetworkName)
}

func testAccContainerClusterDatasource_skipNodePoolRefresh(suffix, networkName, subnetworkName string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "kubes" {
name = "tf-test-cluster-%s"
location = "us-central1-a"
initial_node_count = 1

network = "%s"
subnetwork = "%s"

deletion_protection = false
}

data "google_container_cluster" "kubes" {
name = google_container_cluster.kubes.name
location = google_container_cluster.kubes.location

skip_node_pool_refresh = true
}
`, suffix, networkName, subnetworkName)
}

func testAccContainerClusterDatasource_regional(suffix, networkName, subnetworkName string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "kubes" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ favour of `location`.
* `region` (Optional) - The region this cluster has been created in. Deprecated
in favour of `location`.

* `skip_node_pool_refresh` (Optional) - Whether to skip refreshing the GKE
cluster's node pool list during the data source read. Setting this to `true`
prevents the provider from querying the GKE API for node pools, which resolves
long read times on clusters with a large number of node pools. When enabled,
the `node_pool` attribute will be empty (`[]`), even if node pools exist. See
[the resource documentation](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_cluster)
for details.

- - -

* `project` - (Optional) The project in which the resource belongs. If it
Expand Down
Loading