Skip to content

Commit cccc395

Browse files
modular-magicianmelinath
authored andcommitted
fix: check if Bigtable cluster zones are affected by partial unavailability
1 parent 7239035 commit cccc395

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

google-beta/resource_bigtable_instance.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"log"
7+
"strings"
78

89
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
910
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -259,7 +260,17 @@ func resourceBigtableInstanceRead(d *schema.ResourceData, meta interface{}) erro
259260

260261
clusters, err := c.Clusters(ctx, instance.Name)
261262
if err != nil {
262-
return fmt.Errorf("Error retrieving instance clusters. %s", err)
263+
partiallyUnavailableErr, ok := err.(bigtable.ErrPartiallyUnavailable)
264+
265+
if !ok {
266+
return fmt.Errorf("Error retrieving instance clusters. %s", err)
267+
}
268+
269+
unavailableClusterZones := getUnavailableClusterZones(d.Get("cluster").([]interface{}), partiallyUnavailableErr.Locations)
270+
271+
if len(unavailableClusterZones) > 0 {
272+
return fmt.Errorf("Error retrieving instance clusters. The following zones are unavailable: %s", strings.Join(unavailableClusterZones, ", "))
273+
}
263274
}
264275

265276
clustersNewState := []map[string]interface{}{}
@@ -404,6 +415,23 @@ func flattenBigtableCluster(c *bigtable.ClusterInfo) map[string]interface{} {
404415
return cluster
405416
}
406417

418+
func getUnavailableClusterZones(clusters []interface{}, unavailableZones []string) []string {
419+
var zones []string
420+
421+
for _, c := range clusters {
422+
cluster := c.(map[string]interface{})
423+
zone := cluster["zone"].(string)
424+
425+
for _, unavailableZone := range unavailableZones {
426+
if zone == unavailableZone {
427+
zones = append(zones, zone)
428+
break
429+
}
430+
}
431+
}
432+
return zones
433+
}
434+
407435
func expandBigtableClusters(clusters []interface{}, instanceID string, config *Config) ([]bigtable.ClusterConfig, error) {
408436
results := make([]bigtable.ClusterConfig, 0, len(clusters))
409437
for _, c := range clusters {

0 commit comments

Comments
 (0)