mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-06 17:16:44 +00:00
Merge pull request #11650 from danawillow/google-container
provider/google: set additional_zones to computed and disallow the original zone from appearing in the list
This commit is contained in:
commit
30b83cb0a6
@ -95,6 +95,7 @@ func resourceContainerCluster() *schema.Resource {
|
|||||||
"additional_zones": &schema.Schema{
|
"additional_zones": &schema.Schema{
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeList,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
Elem: &schema.Schema{Type: schema.TypeString},
|
Elem: &schema.Schema{Type: schema.TypeString},
|
||||||
},
|
},
|
||||||
@ -292,18 +293,14 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
|
|||||||
if v, ok := d.GetOk("additional_zones"); ok {
|
if v, ok := d.GetOk("additional_zones"); ok {
|
||||||
locationsList := v.([]interface{})
|
locationsList := v.([]interface{})
|
||||||
locations := []string{}
|
locations := []string{}
|
||||||
zoneInLocations := false
|
|
||||||
for _, v := range locationsList {
|
for _, v := range locationsList {
|
||||||
location := v.(string)
|
location := v.(string)
|
||||||
locations = append(locations, location)
|
locations = append(locations, location)
|
||||||
if location == zoneName {
|
if location == zoneName {
|
||||||
zoneInLocations = true
|
return fmt.Errorf("additional_zones should not contain the original 'zone'.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !zoneInLocations {
|
locations = append(locations, zoneName)
|
||||||
// zone must be in locations if specified separately
|
|
||||||
locations = append(locations, zoneName)
|
|
||||||
}
|
|
||||||
cluster.Locations = locations
|
cluster.Locations = locations
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -444,7 +441,17 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro
|
|||||||
|
|
||||||
d.Set("name", cluster.Name)
|
d.Set("name", cluster.Name)
|
||||||
d.Set("zone", cluster.Zone)
|
d.Set("zone", cluster.Zone)
|
||||||
d.Set("additional_zones", cluster.Locations)
|
|
||||||
|
locations := []string{}
|
||||||
|
if len(cluster.Locations) > 1 {
|
||||||
|
for _, location := range cluster.Locations {
|
||||||
|
if location != cluster.Zone {
|
||||||
|
locations = append(locations, location)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
d.Set("additional_zones", locations)
|
||||||
|
|
||||||
d.Set("endpoint", cluster.Endpoint)
|
d.Set("endpoint", cluster.Endpoint)
|
||||||
|
|
||||||
masterAuth := []map[string]interface{}{
|
masterAuth := []map[string]interface{}{
|
||||||
|
@ -39,7 +39,7 @@ func TestAccContainerCluster_withAdditionalZones(t *testing.T) {
|
|||||||
testAccCheckContainerClusterExists(
|
testAccCheckContainerClusterExists(
|
||||||
"google_container_cluster.with_additional_zones"),
|
"google_container_cluster.with_additional_zones"),
|
||||||
testAccCheckContainerClusterAdditionalZonesExist(
|
testAccCheckContainerClusterAdditionalZonesExist(
|
||||||
"google_container_cluster.with_additional_zones"),
|
"google_container_cluster.with_additional_zones", 2),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -163,23 +163,19 @@ func testAccCheckContainerClusterExists(n string) resource.TestCheckFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckContainerClusterAdditionalZonesExist(n string) resource.TestCheckFunc {
|
func testAccCheckContainerClusterAdditionalZonesExist(n string, num int) 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]
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("Not found: %s", n)
|
return fmt.Errorf("Not found: %s", n)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
additionalZonesSize, err := strconv.Atoi(rs.Primary.Attributes["additional_zones.#"])
|
||||||
additionalZonesSize int
|
if err != nil {
|
||||||
err error
|
|
||||||
)
|
|
||||||
|
|
||||||
if additionalZonesSize, err = strconv.Atoi(rs.Primary.Attributes["additional_zones.#"]); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if additionalZonesSize != 2 {
|
if additionalZonesSize != num {
|
||||||
return fmt.Errorf("number of additional zones did not match 2")
|
return fmt.Errorf("number of additional zones did not match %d, was %d", num, additionalZonesSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user