Skip to content

Commit 038cd0b

Browse files
authored
Add support for regional cluster in datasource (#1441)
1 parent 6a1d446 commit 038cd0b

3 files changed

+52
-18
lines changed

google/data_source_google_container_cluster.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ func dataSourceGoogleContainerCluster() *schema.Resource {
99
dsSchema := datasourceSchemaFromResourceSchema(resourceContainerCluster().Schema)
1010

1111
// Set 'Required' schema elements
12-
addRequiredFieldsToSchema(dsSchema, "name", "zone")
12+
addRequiredFieldsToSchema(dsSchema, "name")
1313

1414
// Set 'Optional' schema elements
15-
addOptionalFieldsToSchema(dsSchema, "project")
15+
addOptionalFieldsToSchema(dsSchema, "project", "zone", "region")
1616

1717
return &schema.Resource{
1818
Read: datasourceContainerClusterRead,

google/data_source_google_container_cluster_test.go

+49-15
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,32 @@ import (
99
"github.com/hashicorp/terraform/terraform"
1010
)
1111

12-
func TestAccContainerClusterDatasource_basic(t *testing.T) {
12+
func TestAccContainerClusterDatasource_zonal(t *testing.T) {
1313
t.Parallel()
1414

1515
resource.Test(t, resource.TestCase{
1616
PreCheck: func() { testAccPreCheck(t) },
1717
Providers: testAccProviders,
1818
Steps: []resource.TestStep{
1919
{
20-
Config: testAccContainerClusterDatasourceConfig,
20+
Config: testAccContainerClusterDatasource_zonal(),
21+
Check: resource.ComposeTestCheckFunc(
22+
testAccDataSourceGoogleContainerClusterCheck("data.google_container_cluster.kubes", "google_container_cluster.kubes"),
23+
),
24+
},
25+
},
26+
})
27+
}
28+
29+
func TestAccContainerClusterDatasource_regional(t *testing.T) {
30+
t.Parallel()
31+
32+
resource.Test(t, resource.TestCase{
33+
PreCheck: func() { testAccPreCheck(t) },
34+
Providers: testAccProviders,
35+
Steps: []resource.TestStep{
36+
{
37+
Config: testAccContainerClusterDatasource_regional(),
2138
Check: resource.ComposeTestCheckFunc(
2239
testAccDataSourceGoogleContainerClusterCheck("data.google_container_cluster.kubes", "google_container_cluster.kubes"),
2340
),
@@ -88,20 +105,37 @@ func testAccDataSourceGoogleContainerClusterCheck(dataSourceName string, resourc
88105
}
89106
}
90107

91-
var testAccContainerClusterDatasourceConfig = fmt.Sprintf(`
92-
resource "google_container_cluster" "kubes" {
93-
name = "cluster-test-%s"
94-
zone = "us-central1-a"
95-
initial_node_count = 1
108+
func testAccContainerClusterDatasource_zonal() string {
109+
return fmt.Sprintf(`
110+
resource "google_container_cluster" "kubes" {
111+
name = "cluster-test-%s"
112+
zone = "us-central1-a"
113+
initial_node_count = 1
96114
97-
master_auth {
98-
username = "mr.yoda"
99-
password = "adoy.rm.123456789"
100-
}
115+
master_auth {
116+
username = "mr.yoda"
117+
password = "adoy.rm.123456789"
101118
}
119+
}
102120
103-
data "google_container_cluster" "kubes" {
104-
name = "${google_container_cluster.kubes.name}"
105-
zone = "${google_container_cluster.kubes.zone}"
106-
}
121+
data "google_container_cluster" "kubes" {
122+
name = "${google_container_cluster.kubes.name}"
123+
zone = "${google_container_cluster.kubes.zone}"
124+
}
107125
`, acctest.RandString(10))
126+
}
127+
128+
func testAccContainerClusterDatasource_regional() string {
129+
return fmt.Sprintf(`
130+
resource "google_container_cluster" "kubes" {
131+
name = "cluster-test-%s"
132+
region = "us-central1"
133+
initial_node_count = 1
134+
}
135+
136+
data "google_container_cluster" "kubes" {
137+
name = "${google_container_cluster.kubes.name}"
138+
region = "${google_container_cluster.kubes.region}"
139+
}
140+
`, acctest.RandString(10))
141+
}

website/docs/d/google_container_cluster.html.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ The following arguments are supported:
4949

5050
* `name` - The name of the cluster.
5151

52-
* `zone` - The zones this cluster has been created in.
52+
* `zone` or `region` - The zone or region this cluster has been created in.
5353

5454
- - -
5555

0 commit comments

Comments
 (0)