|
4 | 4 | "context" |
5 | 5 | "fmt" |
6 | 6 | "log" |
| 7 | + "strings" |
7 | 8 |
|
8 | 9 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" |
9 | 10 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
@@ -259,7 +260,17 @@ func resourceBigtableInstanceRead(d *schema.ResourceData, meta interface{}) erro |
259 | 260 |
|
260 | 261 | clusters, err := c.Clusters(ctx, instance.Name) |
261 | 262 | 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 | + } |
263 | 274 | } |
264 | 275 |
|
265 | 276 | clustersNewState := []map[string]interface{}{} |
@@ -404,6 +415,23 @@ func flattenBigtableCluster(c *bigtable.ClusterInfo) map[string]interface{} { |
404 | 415 | return cluster |
405 | 416 | } |
406 | 417 |
|
| 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 | + |
407 | 435 | func expandBigtableClusters(clusters []interface{}, instanceID string, config *Config) ([]bigtable.ClusterConfig, error) { |
408 | 436 | results := make([]bigtable.ClusterConfig, 0, len(clusters)) |
409 | 437 | for _, c := range clusters { |
|
0 commit comments