Use beta API location for google_container_engine_versions (#1939)

* use beta API location for  data source

* doc fixes

* use getLocation

* add note to docs about required locations
This commit is contained in:
emily 2018-08-28 11:37:07 -07:00 committed by GitHub
parent f1f0bc97e2
commit 10ec7b2ca9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 7 deletions

View File

@ -19,6 +19,11 @@ func dataSourceGoogleContainerEngineVersions() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"region": {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"zone"},
},
"default_cluster_version": {
Type: schema.TypeString,
Computed: true,
@ -53,12 +58,16 @@ func dataSourceGoogleContainerEngineVersionsRead(d *schema.ResourceData, meta in
return err
}
zone, err := getZone(d, meta.(*Config))
location, err := getLocation(d, config)
if err != nil {
return err
}
if len(location) == 0 {
return fmt.Errorf("Cannot determine location: set zone or region in this data source or at provider-level")
}
resp, err := config.clientContainer.Projects.Zones.GetServerconfig(project, zone).Do()
location = fmt.Sprintf("projects/%s/locations/%s", project, location)
resp, err := config.clientContainerBeta.Projects.Locations.GetServerConfig(location).Do()
if err != nil {
return fmt.Errorf("Error retrieving available container cluster versions: %s", err.Error())
}
@ -66,10 +75,13 @@ func dataSourceGoogleContainerEngineVersionsRead(d *schema.ResourceData, meta in
d.Set("valid_master_versions", resp.ValidMasterVersions)
d.Set("default_cluster_version", resp.DefaultClusterVersion)
d.Set("valid_node_versions", resp.ValidNodeVersions)
d.Set("latest_master_version", resp.ValidMasterVersions[0])
d.Set("latest_node_version", resp.ValidNodeVersions[0])
if len(resp.ValidMasterVersions) > 0 {
d.Set("latest_master_version", resp.ValidMasterVersions[0])
}
if len(resp.ValidNodeVersions) > 0 {
d.Set("latest_node_version", resp.ValidNodeVersions[0])
}
d.SetId(time.Now().UTC().String())
return nil
}

View File

@ -27,6 +27,23 @@ func TestAccContainerEngineVersions_basic(t *testing.T) {
})
}
func TestAccContainerEngineVersions_regional(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckGoogleContainerEngineVersionsRegionalConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckGoogleContainerEngineVersionsMeta("data.google_container_engine_versions.versions"),
),
},
},
})
}
func testAccCheckGoogleContainerEngineVersionsMeta(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
@ -102,3 +119,9 @@ data "google_container_engine_versions" "versions" {
zone = "us-central1-b"
}
`
var testAccCheckGoogleContainerEngineVersionsRegionalConfig = `
data "google_container_engine_versions" "versions" {
region = "us-central1"
}
`

View File

@ -8,7 +8,7 @@ description: |-
# google\_container\_engine\_versions
Provides access to available Google Container Engine versions in a zone for a given project.
Provides access to available Google Container Engine versions in a zone or region for a given project.
```hcl
data "google_container_engine_versions" "central1b" {
@ -32,7 +32,13 @@ resource "google_container_cluster" "foo" {
The following arguments are supported:
* `zone` (required) - Zone to list available cluster versions for. Should match the zone the cluster will be deployed in.
* `zone` (optional) - Zone to list available cluster versions for. Should match the zone the cluster will be deployed in.
If not specified, the provider-level zone is used. One of zone, region, or provider-level zone is required.
* `region` (optional) - Region to list available cluster versions for. Should match the region the cluster will be deployed in.
For regional clusters, this value must be specified and cannot be inferred from provider-level region. One of zone,
region, or provider-level zone is required.
* `project` (optional) - ID of the project to list available cluster versions for. Should match the project the cluster will be deployed to.
Defaults to the project that the provider is authenticated with.