mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-08 19:18:30 +00:00
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:
parent
f1f0bc97e2
commit
10ec7b2ca9
|
@ -19,6 +19,11 @@ func dataSourceGoogleContainerEngineVersions() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
},
|
},
|
||||||
|
"region": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
ConflictsWith: []string{"zone"},
|
||||||
|
},
|
||||||
"default_cluster_version": {
|
"default_cluster_version": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
|
@ -53,12 +58,16 @@ func dataSourceGoogleContainerEngineVersionsRead(d *schema.ResourceData, meta in
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
zone, err := getZone(d, meta.(*Config))
|
location, err := getLocation(d, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("Error retrieving available container cluster versions: %s", err.Error())
|
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("valid_master_versions", resp.ValidMasterVersions)
|
||||||
d.Set("default_cluster_version", resp.DefaultClusterVersion)
|
d.Set("default_cluster_version", resp.DefaultClusterVersion)
|
||||||
d.Set("valid_node_versions", resp.ValidNodeVersions)
|
d.Set("valid_node_versions", resp.ValidNodeVersions)
|
||||||
|
if len(resp.ValidMasterVersions) > 0 {
|
||||||
d.Set("latest_master_version", 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.Set("latest_node_version", resp.ValidNodeVersions[0])
|
||||||
|
}
|
||||||
|
|
||||||
d.SetId(time.Now().UTC().String())
|
d.SetId(time.Now().UTC().String())
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
func testAccCheckGoogleContainerEngineVersionsMeta(n string) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[n]
|
rs, ok := s.RootModule().Resources[n]
|
||||||
|
@ -102,3 +119,9 @@ data "google_container_engine_versions" "versions" {
|
||||||
zone = "us-central1-b"
|
zone = "us-central1-b"
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
var testAccCheckGoogleContainerEngineVersionsRegionalConfig = `
|
||||||
|
data "google_container_engine_versions" "versions" {
|
||||||
|
region = "us-central1"
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
|
@ -8,7 +8,7 @@ description: |-
|
||||||
|
|
||||||
# google\_container\_engine\_versions
|
# 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
|
```hcl
|
||||||
data "google_container_engine_versions" "central1b" {
|
data "google_container_engine_versions" "central1b" {
|
||||||
|
@ -32,7 +32,13 @@ resource "google_container_cluster" "foo" {
|
||||||
|
|
||||||
The following arguments are supported:
|
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.
|
* `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.
|
Defaults to the project that the provider is authenticated with.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user