mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-05 17:52:38 +00:00
56dfb7d8f8
Add a data source for listing available versions for Container Engine clusters or retrieving the latest available version. This is mostly to support our tests for specifying a version for cluster creation; the withVersion test has been updated to use the data source, meaning it will stop failing on us as new versions get released.
98 lines
2.6 KiB
Go
98 lines
2.6 KiB
Go
package google
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"strconv"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
func TestAccGoogleContainerVersions_basic(t *testing.T) {
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: testAccCheckGoogleContainerVersionsConfig,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckGoogleContainerVersionsMeta("data.google_container_versions.versions"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func testAccCheckGoogleContainerVersionsMeta(n string) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
rs, ok := s.RootModule().Resources[n]
|
|
if !ok {
|
|
return fmt.Errorf("Can't find versions data source: %s", n)
|
|
}
|
|
|
|
if rs.Primary.ID == "" {
|
|
return errors.New("versions data source ID not set.")
|
|
}
|
|
|
|
nodeCount, ok := rs.Primary.Attributes["valid_node_versions.#"]
|
|
if !ok {
|
|
return errors.New("can't find 'valid_node_versions' attribute")
|
|
}
|
|
|
|
noOfNodes, err := strconv.Atoi(nodeCount)
|
|
if err != nil {
|
|
return errors.New("failed to read number of valid node versions")
|
|
}
|
|
if noOfNodes < 2 {
|
|
return fmt.Errorf("expected at least 2 valid node versions, received %d, this is most likely a bug",
|
|
noOfNodes)
|
|
}
|
|
|
|
for i := 0; i < noOfNodes; i++ {
|
|
idx := "valid_node_versions." + strconv.Itoa(i)
|
|
v, ok := rs.Primary.Attributes[idx]
|
|
if !ok {
|
|
return fmt.Errorf("valid node versions list is corrupt (%q not found), this is definitely a bug", idx)
|
|
}
|
|
if len(v) < 1 {
|
|
return fmt.Errorf("Empty node version (%q), this is definitely a bug", idx)
|
|
}
|
|
}
|
|
|
|
masterCount, ok := rs.Primary.Attributes["valid_master_versions.#"]
|
|
if !ok {
|
|
return errors.New("can't find 'valid_master_versions' attribute")
|
|
}
|
|
|
|
noOfMasters, err := strconv.Atoi(masterCount)
|
|
if err != nil {
|
|
return errors.New("failed to read number of valid master versions")
|
|
}
|
|
if noOfMasters < 2 {
|
|
return fmt.Errorf("expected at least 2 valid master versions, received %d, this is most likely a bug",
|
|
noOfMasters)
|
|
}
|
|
|
|
for i := 0; i < noOfMasters; i++ {
|
|
idx := "valid_master_versions." + strconv.Itoa(i)
|
|
v, ok := rs.Primary.Attributes[idx]
|
|
if !ok {
|
|
return fmt.Errorf("valid master versions list is corrupt (%q not found), this is definitely a bug", idx)
|
|
}
|
|
if len(v) < 1 {
|
|
return fmt.Errorf("Empty master version (%q), this is definitely a bug", idx)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
var testAccCheckGoogleContainerVersionsConfig = `
|
|
data "google_container_versions" "versions" {
|
|
zone = "us-central1-b"
|
|
}
|
|
`
|