mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-04 17:51:11 +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)
|
dsSchema := datasourceSchemaFromResourceSchema(resourceContainerCluster().Schema)
|
||||||
|
|
||||||
// Set 'Required' schema elements
|
// Set 'Required' schema elements
|
||||||
addRequiredFieldsToSchema(dsSchema, "name", "zone")
|
addRequiredFieldsToSchema(dsSchema, "name")
|
||||||
|
|
||||||
// Set 'Optional' schema elements
|
// Set 'Optional' schema elements
|
||||||
addOptionalFieldsToSchema(dsSchema, "project")
|
addOptionalFieldsToSchema(dsSchema, "project", "zone", "region")
|
||||||
|
|
||||||
return &schema.Resource{
|
return &schema.Resource{
|
||||||
Read: datasourceContainerClusterRead,
|
Read: datasourceContainerClusterRead,
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccContainerClusterDatasource_basic(t *testing.T) {
|
func TestAccContainerClusterDatasource_zonal(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
@ -17,7 +17,24 @@ func TestAccContainerClusterDatasource_basic(t *testing.T) {
|
|||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
Steps: []resource.TestStep{
|
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(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccDataSourceGoogleContainerClusterCheck("data.google_container_cluster.kubes", "google_container_cluster.kubes"),
|
testAccDataSourceGoogleContainerClusterCheck("data.google_container_cluster.kubes", "google_container_cluster.kubes"),
|
||||||
),
|
),
|
||||||
@ -88,20 +105,37 @@ func testAccDataSourceGoogleContainerClusterCheck(dataSourceName string, resourc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var testAccContainerClusterDatasourceConfig = fmt.Sprintf(`
|
func testAccContainerClusterDatasource_zonal() string {
|
||||||
resource "google_container_cluster" "kubes" {
|
return fmt.Sprintf(`
|
||||||
name = "cluster-test-%s"
|
resource "google_container_cluster" "kubes" {
|
||||||
zone = "us-central1-a"
|
name = "cluster-test-%s"
|
||||||
initial_node_count = 1
|
zone = "us-central1-a"
|
||||||
|
initial_node_count = 1
|
||||||
|
|
||||||
master_auth {
|
master_auth {
|
||||||
username = "mr.yoda"
|
username = "mr.yoda"
|
||||||
password = "adoy.rm.123456789"
|
password = "adoy.rm.123456789"
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
data "google_container_cluster" "kubes" {
|
data "google_container_cluster" "kubes" {
|
||||||
name = "${google_container_cluster.kubes.name}"
|
name = "${google_container_cluster.kubes.name}"
|
||||||
zone = "${google_container_cluster.kubes.zone}"
|
zone = "${google_container_cluster.kubes.zone}"
|
||||||
}
|
}
|
||||||
`, acctest.RandString(10))
|
`, 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.
|
* `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