From 038cd0b7d1bfab201509fb305b957b64acc9b3bf Mon Sep 17 00:00:00 2001 From: Vincent Roseberry Date: Mon, 7 May 2018 15:02:14 -0700 Subject: [PATCH] Add support for regional cluster in datasource (#1441) --- .../data_source_google_container_cluster.go | 4 +- ...ta_source_google_container_cluster_test.go | 64 ++++++++++++++----- .../d/google_container_cluster.html.markdown | 2 +- 3 files changed, 52 insertions(+), 18 deletions(-) diff --git a/google/data_source_google_container_cluster.go b/google/data_source_google_container_cluster.go index db7644f0..91d8159c 100644 --- a/google/data_source_google_container_cluster.go +++ b/google/data_source_google_container_cluster.go @@ -9,10 +9,10 @@ func dataSourceGoogleContainerCluster() *schema.Resource { dsSchema := datasourceSchemaFromResourceSchema(resourceContainerCluster().Schema) // Set 'Required' schema elements - addRequiredFieldsToSchema(dsSchema, "name", "zone") + addRequiredFieldsToSchema(dsSchema, "name") // Set 'Optional' schema elements - addOptionalFieldsToSchema(dsSchema, "project") + addOptionalFieldsToSchema(dsSchema, "project", "zone", "region") return &schema.Resource{ Read: datasourceContainerClusterRead, diff --git a/google/data_source_google_container_cluster_test.go b/google/data_source_google_container_cluster_test.go index bb29b471..88e35cb8 100644 --- a/google/data_source_google_container_cluster_test.go +++ b/google/data_source_google_container_cluster_test.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform/terraform" ) -func TestAccContainerClusterDatasource_basic(t *testing.T) { +func TestAccContainerClusterDatasource_zonal(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ @@ -17,7 +17,24 @@ func TestAccContainerClusterDatasource_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccContainerClusterDatasourceConfig, + Config: testAccContainerClusterDatasource_zonal(), + Check: resource.ComposeTestCheckFunc( + testAccDataSourceGoogleContainerClusterCheck("data.google_container_cluster.kubes", "google_container_cluster.kubes"), + ), + }, + }, + }) +} + +func TestAccContainerClusterDatasource_regional(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccContainerClusterDatasource_regional(), Check: resource.ComposeTestCheckFunc( testAccDataSourceGoogleContainerClusterCheck("data.google_container_cluster.kubes", "google_container_cluster.kubes"), ), @@ -88,20 +105,37 @@ func testAccDataSourceGoogleContainerClusterCheck(dataSourceName string, resourc } } -var testAccContainerClusterDatasourceConfig = fmt.Sprintf(` - resource "google_container_cluster" "kubes" { - name = "cluster-test-%s" - zone = "us-central1-a" - initial_node_count = 1 +func testAccContainerClusterDatasource_zonal() string { + return fmt.Sprintf(` +resource "google_container_cluster" "kubes" { + name = "cluster-test-%s" + zone = "us-central1-a" + initial_node_count = 1 - master_auth { - username = "mr.yoda" - password = "adoy.rm.123456789" - } + master_auth { + username = "mr.yoda" + password = "adoy.rm.123456789" } +} - data "google_container_cluster" "kubes" { - name = "${google_container_cluster.kubes.name}" - zone = "${google_container_cluster.kubes.zone}" - } +data "google_container_cluster" "kubes" { + name = "${google_container_cluster.kubes.name}" + zone = "${google_container_cluster.kubes.zone}" +} `, acctest.RandString(10)) +} + +func testAccContainerClusterDatasource_regional() string { + return fmt.Sprintf(` +resource "google_container_cluster" "kubes" { + name = "cluster-test-%s" + region = "us-central1" + initial_node_count = 1 +} + +data "google_container_cluster" "kubes" { + name = "${google_container_cluster.kubes.name}" + region = "${google_container_cluster.kubes.region}" +} +`, acctest.RandString(10)) +} diff --git a/website/docs/d/google_container_cluster.html.markdown b/website/docs/d/google_container_cluster.html.markdown index 94be832c..091f8f11 100644 --- a/website/docs/d/google_container_cluster.html.markdown +++ b/website/docs/d/google_container_cluster.html.markdown @@ -49,7 +49,7 @@ The following arguments are supported: * `name` - The name of the cluster. -* `zone` - The zones this cluster has been created in. +* `zone` or `region` - The zone or region this cluster has been created in. - - -