mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-03 01:01:06 +00:00
Add support for regional cluster in datasource (#1441)
This commit is contained in:
parent
6a1d446691
commit
038cd0b7d1
@ -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,
|
||||
|
@ -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,7 +105,8 @@ func testAccDataSourceGoogleContainerClusterCheck(dataSourceName string, resourc
|
||||
}
|
||||
}
|
||||
|
||||
var testAccContainerClusterDatasourceConfig = fmt.Sprintf(`
|
||||
func testAccContainerClusterDatasource_zonal() string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_container_cluster" "kubes" {
|
||||
name = "cluster-test-%s"
|
||||
zone = "us-central1-a"
|
||||
@ -105,3 +123,19 @@ var testAccContainerClusterDatasourceConfig = fmt.Sprintf(`
|
||||
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))
|
||||
}
|
||||
|
@ -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.
|
||||
|
||||
- - -
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user