From f2583d730426d71e3102db05841327279f845de7 Mon Sep 17 00:00:00 2001 From: "Praveen K. Gostu" Date: Thu, 9 Aug 2018 12:49:14 +0530 Subject: [PATCH] handle cluster import Handle import for cluster with zero workers in default worker pool --- ibm/resource_ibm_container_cluster.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/ibm/resource_ibm_container_cluster.go b/ibm/resource_ibm_container_cluster.go index adc911b22d..a30b83c114 100644 --- a/ibm/resource_ibm_container_cluster.go +++ b/ibm/resource_ibm_container_cluster.go @@ -488,14 +488,18 @@ func resourceIBMContainerClusterRead(d *schema.ResourceData, meta interface{}) e return fmt.Errorf("Error retrieving workers of default worker pool for cluster: %s", err) } - hardware := workersByPool[0].Isolation - switch strings.ToLower(hardware) { - case "": - hardware = hardwareShared - case isolationPrivate: - hardware = hardwareDedicated - case isolationPublic: - hardware = hardwareShared + if len(workersByPool) > 0 { + hardware := workersByPool[0].Isolation + switch strings.ToLower(hardware) { + case "": + hardware = hardwareShared + case isolationPrivate: + hardware = hardwareDedicated + case isolationPublic: + hardware = hardwareShared + } + d.Set("isolation", workersByPool[0].Isolation) + d.Set("hardware", hardware) } defaultWorkerPool, err := workerPoolsAPI.GetWorkerPool(clusterID, defaultWorkerPool, targetEnv) @@ -510,8 +514,6 @@ func resourceIBMContainerClusterRead(d *schema.ResourceData, meta interface{}) e } } d.Set("worker_pools", flattenWorkerPools(workerPools)) - d.Set("hardware", hardware) - d.Set("isolation", workersByPool[0].Isolation) } albs, err := albsAPI.ListClusterALBs(clusterID, targetEnv)