Add support for regional cluster in datasource (#1441)

This commit is contained in:
Vincent Roseberry 2018-05-07 15:02:14 -07:00 committed by GitHub
parent 6a1d446691
commit 038cd0b7d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 18 deletions

View File

@ -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,

View File

@ -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))
}

View File

@ -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.
- - -