From 278ce016ee8f50dc019075d68805161b2ff13522 Mon Sep 17 00:00:00 2001
From: Sivaanand Murugesan <sivaanand.m@gmail.com>
Date: Sat, 1 Jul 2023 00:54:02 +0530
Subject: [PATCH] PLT-536:Added fix for machine pool type set empty item issue
 (#306)

* PLT-536:Added fix for machine pool type set empty item issue

* Update spectrocloud/resource_cluster_aks.go

Co-authored-by: nikchern <nikolay@spectrocloud.com>

* Update spectrocloud/resource_cluster_aws.go

* Update spectrocloud/resource_cluster_azure.go

* Update spectrocloud/resource_cluster_coxedge.go

* Update spectrocloud/resource_cluster_edge_native.go

* Update spectrocloud/resource_cluster_edge_vsphere.go

* Update spectrocloud/resource_cluster_eks.go

* Update spectrocloud/resource_cluster_gcp.go

* Update spectrocloud/resource_cluster_libvirt.go

* Update spectrocloud/resource_cluster_openstack.go

* Update spectrocloud/resource_cluster_tke.go

* Update spectrocloud/resource_cluster_virtual.go

---------

Co-authored-by: nikchern <nikolay@spectrocloud.com>
---
 spectrocloud/resource_cluster_aks.go          | 35 +++++++------
 spectrocloud/resource_cluster_aws.go          | 43 ++++++++--------
 spectrocloud/resource_cluster_azure.go        | 41 +++++++++-------
 spectrocloud/resource_cluster_coxedge.go      | 41 +++++++++-------
 spectrocloud/resource_cluster_edge_native.go  | 47 +++++++++---------
 spectrocloud/resource_cluster_edge_vsphere.go | 49 ++++++++++---------
 spectrocloud/resource_cluster_eks.go          | 41 +++++++++-------
 spectrocloud/resource_cluster_gcp.go          | 41 +++++++++-------
 spectrocloud/resource_cluster_libvirt.go      | 45 +++++++++--------
 spectrocloud/resource_cluster_openstack.go    | 41 +++++++++-------
 spectrocloud/resource_cluster_tke.go          | 38 +++++++-------
 spectrocloud/resource_cluster_virtual.go      | 38 +++++++-------
 12 files changed, 269 insertions(+), 231 deletions(-)

diff --git a/spectrocloud/resource_cluster_aks.go b/spectrocloud/resource_cluster_aks.go
index 7ac9719a..3bbdc4dc 100644
--- a/spectrocloud/resource_cluster_aks.go
+++ b/spectrocloud/resource_cluster_aks.go
@@ -335,23 +335,26 @@ func resourceClusterAksUpdate(ctx context.Context, d *schema.ResourceData, m int
 
 		for _, mp := range ns {
 			machinePoolResource := mp.(map[string]interface{})
-			name := machinePoolResource["name"].(string)
-			hash := resourceMachinePoolAksHash(machinePoolResource)
-
-			machinePool := toMachinePoolAks(machinePoolResource)
-
-			var err error
-			if oldMachinePool, ok := osMap[name]; !ok {
-				log.Printf("Create machine pool %s", name)
-				err = c.CreateMachinePoolAks(cloudConfigId, machinePool)
-			} else if hash != resourceMachinePoolAksHash(oldMachinePool) {
-				log.Printf("Change in machine pool %s", name)
-				err = c.UpdateMachinePoolAks(cloudConfigId, machinePool)
+                        // since known issue in TF SDK: https://github.com/hashicorp/terraform-plugin-sdk/issues/588
+			if machinePoolResource["name"].(string) != "" {
+				name := machinePoolResource["name"].(string)
+				hash := resourceMachinePoolAksHash(machinePoolResource)
+
+				machinePool := toMachinePoolAks(machinePoolResource)
+
+				var err error
+				if oldMachinePool, ok := osMap[name]; !ok {
+					log.Printf("Create machine pool %s", name)
+					err = c.CreateMachinePoolAks(cloudConfigId, machinePool)
+				} else if hash != resourceMachinePoolAksHash(oldMachinePool) {
+					log.Printf("Change in machine pool %s", name)
+					err = c.UpdateMachinePoolAks(cloudConfigId, machinePool)
+				}
+				if err != nil {
+					return diag.FromErr(err)
+				}
+				delete(osMap, name)
 			}
-			if err != nil {
-				return diag.FromErr(err)
-			}
-			delete(osMap, name)
 		}
 
 		// Deleted old machine pools
diff --git a/spectrocloud/resource_cluster_aws.go b/spectrocloud/resource_cluster_aws.go
index 0066777d..c7a5f773 100644
--- a/spectrocloud/resource_cluster_aws.go
+++ b/spectrocloud/resource_cluster_aws.go
@@ -346,27 +346,30 @@ func resourceClusterAwsUpdate(ctx context.Context, d *schema.ResourceData, m int
 
 		for _, mp := range ns.List() {
 			machinePoolResource := mp.(map[string]interface{})
-			name := machinePoolResource["name"].(string)
-			if name != "" {
-				hash := resourceMachinePoolAwsHash(machinePoolResource)
-				vpcId := d.Get("cloud_config").([]interface{})[0].(map[string]interface{})["vpc_id"]
-				machinePool := toMachinePoolAws(machinePoolResource, vpcId.(string))
-
-				var err error
-				if oldMachinePool, ok := osMap[name]; !ok {
-					log.Printf("Create machine pool %s", name)
-					err = c.CreateMachinePoolAws(cloudConfigId, machinePool)
-				} else if hash != resourceMachinePoolAwsHash(oldMachinePool) {
-					log.Printf("Change in machine pool %s", name)
-					err = c.UpdateMachinePoolAws(cloudConfigId, machinePool)
+                        // since known issue in TF SDK: https://github.com/hashicorp/terraform-plugin-sdk/issues/588
+			if machinePoolResource["name"].(string) != "" {
+				name := machinePoolResource["name"].(string)
+				if name != "" {
+					hash := resourceMachinePoolAwsHash(machinePoolResource)
+					vpcId := d.Get("cloud_config").([]interface{})[0].(map[string]interface{})["vpc_id"]
+					machinePool := toMachinePoolAws(machinePoolResource, vpcId.(string))
+
+					var err error
+					if oldMachinePool, ok := osMap[name]; !ok {
+						log.Printf("Create machine pool %s", name)
+						err = c.CreateMachinePoolAws(cloudConfigId, machinePool)
+					} else if hash != resourceMachinePoolAwsHash(oldMachinePool) {
+						log.Printf("Change in machine pool %s", name)
+						err = c.UpdateMachinePoolAws(cloudConfigId, machinePool)
+					}
+
+					if err != nil {
+						return diag.FromErr(err)
+					}
+
+					// Processed (if exists)
+					delete(osMap, name)
 				}
-
-				if err != nil {
-					return diag.FromErr(err)
-				}
-
-				// Processed (if exists)
-				delete(osMap, name)
 			}
 		}
 
diff --git a/spectrocloud/resource_cluster_azure.go b/spectrocloud/resource_cluster_azure.go
index 879d3ba7..2dc7da21 100644
--- a/spectrocloud/resource_cluster_azure.go
+++ b/spectrocloud/resource_cluster_azure.go
@@ -388,26 +388,29 @@ func resourceClusterAzureUpdate(ctx context.Context, d *schema.ResourceData, m i
 
 		for _, mp := range ns.List() {
 			machinePoolResource := mp.(map[string]interface{})
-			name := machinePoolResource["name"].(string)
-			hash := resourceMachinePoolAzureHash(machinePoolResource)
-
-			machinePool := toMachinePoolAzure(machinePoolResource)
-
-			var err error
-			if oldMachinePool, ok := osMap[name]; !ok {
-				log.Printf("Create machine pool %s", name)
-				err = c.CreateMachinePoolAzure(cloudConfigId, machinePool)
-			} else if hash != resourceMachinePoolAzureHash(oldMachinePool) {
-				log.Printf("Change in machine pool %s", name)
-				err = c.UpdateMachinePoolAzure(cloudConfigId, machinePool)
+                        // since known issue in TF SDK: https://github.com/hashicorp/terraform-plugin-sdk/issues/588
+			if machinePoolResource["name"].(string) != "" {
+				name := machinePoolResource["name"].(string)
+				hash := resourceMachinePoolAzureHash(machinePoolResource)
+
+				machinePool := toMachinePoolAzure(machinePoolResource)
+
+				var err error
+				if oldMachinePool, ok := osMap[name]; !ok {
+					log.Printf("Create machine pool %s", name)
+					err = c.CreateMachinePoolAzure(cloudConfigId, machinePool)
+				} else if hash != resourceMachinePoolAzureHash(oldMachinePool) {
+					log.Printf("Change in machine pool %s", name)
+					err = c.UpdateMachinePoolAzure(cloudConfigId, machinePool)
+				}
+
+				if err != nil {
+					return diag.FromErr(err)
+				}
+
+				// Processed (if exists)
+				delete(osMap, name)
 			}
-
-			if err != nil {
-				return diag.FromErr(err)
-			}
-
-			// Processed (if exists)
-			delete(osMap, name)
 		}
 
 		// Deleted old machine pools
diff --git a/spectrocloud/resource_cluster_coxedge.go b/spectrocloud/resource_cluster_coxedge.go
index 755209f9..c32eb6e1 100644
--- a/spectrocloud/resource_cluster_coxedge.go
+++ b/spectrocloud/resource_cluster_coxedge.go
@@ -563,29 +563,32 @@ func resourceCoxEdgeClusterUpdate(ctx context.Context, d *schema.ResourceData, m
 
 		for _, mp := range ns {
 			machinePoolResource := mp.(map[string]interface{})
-			name := machinePoolResource["name"].(string)
-			hash := resourceMachinePoolCoxEdgeHash(machinePoolResource)
+                       // since known issue in TF SDK: https://github.com/hashicorp/terraform-plugin-sdk/issues/588
+			if machinePoolResource["name"].(string) != "" {
+				name := machinePoolResource["name"].(string)
+				hash := resourceMachinePoolCoxEdgeHash(machinePoolResource)
 
-			machinePool, err := toMachinePoolCoxEdge(machinePoolResource)
-			if err != nil {
-				return diag.FromErr(err)
-			}
+				machinePool, err := toMachinePoolCoxEdge(machinePoolResource)
+				if err != nil {
+					return diag.FromErr(err)
+				}
 
-			if oldMachinePool, ok := osMap[name]; !ok {
-				log.Printf("Create machine pool %s", name)
-				err = c.CreateMachinePoolCoxEdge(cloudConfigId, machinePool)
-			} else if hash != resourceMachinePoolCoxEdgeHash(oldMachinePool) {
-				// TODO
-				log.Printf("Change in machine pool %s", name)
-				err = c.UpdateMachinePoolCoxEdge(cloudConfigId, machinePool)
-			}
+				if oldMachinePool, ok := osMap[name]; !ok {
+					log.Printf("Create machine pool %s", name)
+					err = c.CreateMachinePoolCoxEdge(cloudConfigId, machinePool)
+				} else if hash != resourceMachinePoolCoxEdgeHash(oldMachinePool) {
+					// TODO
+					log.Printf("Change in machine pool %s", name)
+					err = c.UpdateMachinePoolCoxEdge(cloudConfigId, machinePool)
+				}
 
-			if err != nil {
-				return diag.FromErr(err)
-			}
+				if err != nil {
+					return diag.FromErr(err)
+				}
 
-			// Processed (if exists)
-			delete(osMap, name)
+				// Processed (if exists)
+				delete(osMap, name)
+			}
 		}
 
 		// Deleted old machine pools
diff --git a/spectrocloud/resource_cluster_edge_native.go b/spectrocloud/resource_cluster_edge_native.go
index e83ac520..9a8ddd94 100644
--- a/spectrocloud/resource_cluster_edge_native.go
+++ b/spectrocloud/resource_cluster_edge_native.go
@@ -344,29 +344,32 @@ func resourceClusterEdgeNativeUpdate(ctx context.Context, d *schema.ResourceData
 
 		for _, mp := range ns.List() {
 			machinePoolResource := mp.(map[string]interface{})
-			name := machinePoolResource["name"].(string)
-			if name == "" {
-				continue
+                        // since known issue in TF SDK: https://github.com/hashicorp/terraform-plugin-sdk/issues/588
+			if machinePoolResource["name"].(string) != "" {
+				name := machinePoolResource["name"].(string)
+				if name == "" {
+					continue
+				}
+				hash := resourceMachinePoolEdgeNativeHash(machinePoolResource)
+
+				machinePool := toMachinePoolEdgeNative(machinePoolResource)
+
+				var err error
+				if oldMachinePool, ok := osMap[name]; !ok {
+					log.Printf("Create machine pool %s", name)
+					err = c.CreateMachinePoolEdgeNative(cloudConfigId, machinePool)
+				} else if hash != resourceMachinePoolEdgeNativeHash(oldMachinePool) {
+					log.Printf("Change in machine pool %s", name)
+					err = c.UpdateMachinePoolEdgeNative(cloudConfigId, machinePool)
+				}
+
+				if err != nil {
+					return diag.FromErr(err)
+				}
+
+				// Processed (if exists)
+				delete(osMap, name)
 			}
-			hash := resourceMachinePoolEdgeNativeHash(machinePoolResource)
-
-			machinePool := toMachinePoolEdgeNative(machinePoolResource)
-
-			var err error
-			if oldMachinePool, ok := osMap[name]; !ok {
-				log.Printf("Create machine pool %s", name)
-				err = c.CreateMachinePoolEdgeNative(cloudConfigId, machinePool)
-			} else if hash != resourceMachinePoolEdgeNativeHash(oldMachinePool) {
-				log.Printf("Change in machine pool %s", name)
-				err = c.UpdateMachinePoolEdgeNative(cloudConfigId, machinePool)
-			}
-
-			if err != nil {
-				return diag.FromErr(err)
-			}
-
-			// Processed (if exists)
-			delete(osMap, name)
 		}
 
 		// Deleted old machine pools
diff --git a/spectrocloud/resource_cluster_edge_vsphere.go b/spectrocloud/resource_cluster_edge_vsphere.go
index 3416674e..4a04a878 100644
--- a/spectrocloud/resource_cluster_edge_vsphere.go
+++ b/spectrocloud/resource_cluster_edge_vsphere.go
@@ -400,34 +400,37 @@ func resourceClusterEdgeVsphereUpdate(ctx context.Context, d *schema.ResourceDat
 
 		for _, mp := range ns {
 			machinePoolResource := mp.(map[string]interface{})
-			name := machinePoolResource["name"].(string)
-			hash := resourceMachinePoolVsphereHash(machinePoolResource)
-
-			machinePool := toMachinePoolEdgeVsphere(machinePoolResource)
-
-			var err error
-			if oldMachinePool, ok := osMap[name]; !ok {
-				log.Printf("Create machine pool %s", name)
-				err = c.CreateMachinePoolVsphere(cloudConfigId, machinePool)
-			} else if hash != resourceMachinePoolVsphereHash(oldMachinePool) {
-				log.Printf("Change in machine pool %s", name)
-				oldMachinePool := toMachinePoolEdgeVsphere(oldMachinePool)
-				oldPlacements := oldMachinePool.CloudConfig.Placements
-
-				for i, p := range machinePool.CloudConfig.Placements {
-					if len(oldPlacements) > i {
-						p.UID = oldPlacements[i].UID
+                        // since known issue in TF SDK: https://github.com/hashicorp/terraform-plugin-sdk/issues/588
+			if machinePoolResource["name"].(string) != "" {
+				name := machinePoolResource["name"].(string)
+				hash := resourceMachinePoolVsphereHash(machinePoolResource)
+
+				machinePool := toMachinePoolEdgeVsphere(machinePoolResource)
+
+				var err error
+				if oldMachinePool, ok := osMap[name]; !ok {
+					log.Printf("Create machine pool %s", name)
+					err = c.CreateMachinePoolVsphere(cloudConfigId, machinePool)
+				} else if hash != resourceMachinePoolVsphereHash(oldMachinePool) {
+					log.Printf("Change in machine pool %s", name)
+					oldMachinePool := toMachinePoolEdgeVsphere(oldMachinePool)
+					oldPlacements := oldMachinePool.CloudConfig.Placements
+
+					for i, p := range machinePool.CloudConfig.Placements {
+						if len(oldPlacements) > i {
+							p.UID = oldPlacements[i].UID
+						}
 					}
+
+					err = c.UpdateMachinePoolVsphere(cloudConfigId, machinePool)
 				}
 
-				err = c.UpdateMachinePoolVsphere(cloudConfigId, machinePool)
-			}
+				if err != nil {
+					return diag.FromErr(err)
+				}
 
-			if err != nil {
-				return diag.FromErr(err)
+				delete(osMap, name)
 			}
-
-			delete(osMap, name)
 		}
 
 		for _, mp := range osMap {
diff --git a/spectrocloud/resource_cluster_eks.go b/spectrocloud/resource_cluster_eks.go
index 239a57e0..72dc43bf 100644
--- a/spectrocloud/resource_cluster_eks.go
+++ b/spectrocloud/resource_cluster_eks.go
@@ -558,27 +558,30 @@ func resourceClusterEksUpdate(ctx context.Context, d *schema.ResourceData, m int
 
 		for _, mp := range ns {
 			machinePoolResource := mp.(map[string]interface{})
-			name := machinePoolResource["name"].(string)
-			hash := resourceMachinePoolEksHash(machinePoolResource)
-
-			machinePool := toMachinePoolEks(machinePoolResource)
-
-			var err error
-			if oldMachinePool, ok := osMap[name]; !ok {
-				log.Printf("Create machine pool %s", name)
-				err = c.CreateMachinePoolEks(cloudConfigId, machinePool)
-			} else if hash != resourceMachinePoolEksHash(oldMachinePool) {
-				// TODO
-				log.Printf("Change in machine pool %s", name)
-				err = c.UpdateMachinePoolEks(cloudConfigId, machinePool)
-			}
+                        // since known issue in TF SDK: https://github.com/hashicorp/terraform-plugin-sdk/issues/588
+			if machinePoolResource["name"].(string) != "" {
+				name := machinePoolResource["name"].(string)
+				hash := resourceMachinePoolEksHash(machinePoolResource)
+
+				machinePool := toMachinePoolEks(machinePoolResource)
+
+				var err error
+				if oldMachinePool, ok := osMap[name]; !ok {
+					log.Printf("Create machine pool %s", name)
+					err = c.CreateMachinePoolEks(cloudConfigId, machinePool)
+				} else if hash != resourceMachinePoolEksHash(oldMachinePool) {
+					// TODO
+					log.Printf("Change in machine pool %s", name)
+					err = c.UpdateMachinePoolEks(cloudConfigId, machinePool)
+				}
 
-			if err != nil {
-				return diag.FromErr(err)
-			}
+				if err != nil {
+					return diag.FromErr(err)
+				}
 
-			// Processed (if exists)
-			delete(osMap, name)
+				// Processed (if exists)
+				delete(osMap, name)
+			}
 		}
 
 		// Deleted old machine pools
diff --git a/spectrocloud/resource_cluster_gcp.go b/spectrocloud/resource_cluster_gcp.go
index 8c1feb59..8ecf9b69 100644
--- a/spectrocloud/resource_cluster_gcp.go
+++ b/spectrocloud/resource_cluster_gcp.go
@@ -317,26 +317,29 @@ func resourceClusterGcpUpdate(ctx context.Context, d *schema.ResourceData, m int
 
 		for _, mp := range ns.List() {
 			machinePoolResource := mp.(map[string]interface{})
-			name := machinePoolResource["name"].(string)
-			hash := resourceMachinePoolGcpHash(machinePoolResource)
-
-			machinePool := toMachinePoolGcp(machinePoolResource)
-
-			var err error
-			if oldMachinePool, ok := osMap[name]; !ok {
-				log.Printf("Create machine pool %s", name)
-				err = c.CreateMachinePoolGcp(cloudConfigId, machinePool)
-			} else if hash != resourceMachinePoolGcpHash(oldMachinePool) {
-				log.Printf("Change in machine pool %s", name)
-				err = c.UpdateMachinePoolGcp(cloudConfigId, machinePool)
+                        // since known issue in TF SDK: https://github.com/hashicorp/terraform-plugin-sdk/issues/588
+			if machinePoolResource["name"].(string) != "" {
+				name := machinePoolResource["name"].(string)
+				hash := resourceMachinePoolGcpHash(machinePoolResource)
+
+				machinePool := toMachinePoolGcp(machinePoolResource)
+
+				var err error
+				if oldMachinePool, ok := osMap[name]; !ok {
+					log.Printf("Create machine pool %s", name)
+					err = c.CreateMachinePoolGcp(cloudConfigId, machinePool)
+				} else if hash != resourceMachinePoolGcpHash(oldMachinePool) {
+					log.Printf("Change in machine pool %s", name)
+					err = c.UpdateMachinePoolGcp(cloudConfigId, machinePool)
+				}
+
+				if err != nil {
+					return diag.FromErr(err)
+				}
+
+				// Processed (if exists)
+				delete(osMap, name)
 			}
-
-			if err != nil {
-				return diag.FromErr(err)
-			}
-
-			// Processed (if exists)
-			delete(osMap, name)
 		}
 
 		// Deleted old machine pools
diff --git a/spectrocloud/resource_cluster_libvirt.go b/spectrocloud/resource_cluster_libvirt.go
index 18e8be95..085cf623 100644
--- a/spectrocloud/resource_cluster_libvirt.go
+++ b/spectrocloud/resource_cluster_libvirt.go
@@ -514,31 +514,34 @@ func resourceClusterVirtUpdate(ctx context.Context, d *schema.ResourceData, m in
 
 		for _, mp := range ns {
 			machinePoolResource := mp.(map[string]interface{})
-			name := machinePoolResource["name"].(string)
-			if name == "" {
-				continue
-			}
-			hash := resourceMachinePoolLibvirtHash(machinePoolResource)
+                        // since known issue in TF SDK: https://github.com/hashicorp/terraform-plugin-sdk/issues/588
+			if machinePoolResource["name"].(string) != "" {
+				name := machinePoolResource["name"].(string)
+				if name == "" {
+					continue
+				}
+				hash := resourceMachinePoolLibvirtHash(machinePoolResource)
 
-			machinePool, err := toMachinePoolLibvirt(machinePoolResource)
-			if err != nil {
-				return diag.FromErr(err)
-			}
+				machinePool, err := toMachinePoolLibvirt(machinePoolResource)
+				if err != nil {
+					return diag.FromErr(err)
+				}
 
-			if oldMachinePool, ok := osMap[name]; !ok {
-				log.Printf("Create machine pool %s", name)
-				err = c.CreateMachinePoolLibvirt(cloudConfigId, machinePool)
-			} else if hash != resourceMachinePoolLibvirtHash(oldMachinePool) {
-				log.Printf("Change in machine pool %s", name)
-				err = c.UpdateMachinePoolLibvirt(cloudConfigId, machinePool)
-			}
+				if oldMachinePool, ok := osMap[name]; !ok {
+					log.Printf("Create machine pool %s", name)
+					err = c.CreateMachinePoolLibvirt(cloudConfigId, machinePool)
+				} else if hash != resourceMachinePoolLibvirtHash(oldMachinePool) {
+					log.Printf("Change in machine pool %s", name)
+					err = c.UpdateMachinePoolLibvirt(cloudConfigId, machinePool)
+				}
 
-			if err != nil {
-				return diag.FromErr(err)
-			}
+				if err != nil {
+					return diag.FromErr(err)
+				}
 
-			// Processed (if exists)
-			delete(osMap, name)
+				// Processed (if exists)
+				delete(osMap, name)
+			}
 		}
 
 		// Deleted old machine pools
diff --git a/spectrocloud/resource_cluster_openstack.go b/spectrocloud/resource_cluster_openstack.go
index 2ab30e75..656923ce 100644
--- a/spectrocloud/resource_cluster_openstack.go
+++ b/spectrocloud/resource_cluster_openstack.go
@@ -393,26 +393,29 @@ func resourceClusterOpenStackUpdate(ctx context.Context, d *schema.ResourceData,
 
 		for _, mp := range ns {
 			machinePoolResource := mp.(map[string]interface{})
-			name := machinePoolResource["name"].(string)
-			hash := resourceMachinePoolOpenStackHash(machinePoolResource)
-
-			machinePool := toMachinePoolOpenStack(machinePoolResource)
-
-			var err error
-			if oldMachinePool, ok := osMap[name]; !ok {
-				log.Printf("Create machine pool %s", name)
-				err = c.CreateMachinePoolOpenStack(cloudConfigId, machinePool)
-			} else if hash != resourceMachinePoolOpenStackHash(oldMachinePool) {
-				log.Printf("Change in machine pool %s", name)
-				err = c.UpdateMachinePoolOpenStack(cloudConfigId, machinePool)
+                        // since known issue in TF SDK: https://github.com/hashicorp/terraform-plugin-sdk/issues/588
+			if machinePoolResource["name"].(string) != "" {
+				name := machinePoolResource["name"].(string)
+				hash := resourceMachinePoolOpenStackHash(machinePoolResource)
+
+				machinePool := toMachinePoolOpenStack(machinePoolResource)
+
+				var err error
+				if oldMachinePool, ok := osMap[name]; !ok {
+					log.Printf("Create machine pool %s", name)
+					err = c.CreateMachinePoolOpenStack(cloudConfigId, machinePool)
+				} else if hash != resourceMachinePoolOpenStackHash(oldMachinePool) {
+					log.Printf("Change in machine pool %s", name)
+					err = c.UpdateMachinePoolOpenStack(cloudConfigId, machinePool)
+				}
+
+				if err != nil {
+					return diag.FromErr(err)
+				}
+
+				// Processed (if exists)
+				delete(osMap, name)
 			}
-
-			if err != nil {
-				return diag.FromErr(err)
-			}
-
-			// Processed (if exists)
-			delete(osMap, name)
 		}
 
 		// Deleted old machine pools
diff --git a/spectrocloud/resource_cluster_tke.go b/spectrocloud/resource_cluster_tke.go
index 463df799..0eff7acd 100644
--- a/spectrocloud/resource_cluster_tke.go
+++ b/spectrocloud/resource_cluster_tke.go
@@ -338,25 +338,29 @@ func resourceClusterTkeUpdate(ctx context.Context, d *schema.ResourceData, m int
 
 		for _, mp := range ns {
 			machinePoolResource := mp.(map[string]interface{})
-			name := machinePoolResource["name"].(string)
-			hash := resourceMachinePoolTkeHash(machinePoolResource)
-
-			machinePool := toMachinePoolTke(machinePoolResource)
-
-			var err error
-			if oldMachinePool, ok := osMap[name]; !ok {
-				log.Printf("Create machine pool %s", name)
-				err = c.CreateMachinePoolTke(cloudConfigId, machinePool)
-			} else if hash != resourceMachinePoolTkeHash(oldMachinePool) {
-				log.Printf("Change in machine pool %s", name)
-				err = c.UpdateMachinePoolTke(cloudConfigId, machinePool)
+                        // since known issue in TF SDK: https://github.com/hashicorp/terraform-plugin-sdk/issues/588
+			if machinePoolResource["name"].(string) != "" {
+				name := machinePoolResource["name"].(string)
+				hash := resourceMachinePoolTkeHash(machinePoolResource)
+
+				machinePool := toMachinePoolTke(machinePoolResource)
+
+				var err error
+				if oldMachinePool, ok := osMap[name]; !ok {
+					log.Printf("Create machine pool %s", name)
+					err = c.CreateMachinePoolTke(cloudConfigId, machinePool)
+				} else if hash != resourceMachinePoolTkeHash(oldMachinePool) {
+					log.Printf("Change in machine pool %s", name)
+					err = c.UpdateMachinePoolTke(cloudConfigId, machinePool)
+				}
+
+				if err != nil {
+					return diag.FromErr(err)
+				}
+
+				delete(osMap, name)
 			}
 
-			if err != nil {
-				return diag.FromErr(err)
-			}
-
-			delete(osMap, name)
 		}
 
 		for _, mp := range osMap {
diff --git a/spectrocloud/resource_cluster_virtual.go b/spectrocloud/resource_cluster_virtual.go
index f5d60e28..1996cbdc 100644
--- a/spectrocloud/resource_cluster_virtual.go
+++ b/spectrocloud/resource_cluster_virtual.go
@@ -257,25 +257,29 @@ func resourceClusterVirtualUpdate(ctx context.Context, d *schema.ResourceData, m
 
 		for _, mp := range ns.List() {
 			machinePoolResource := mp.(map[string]interface{})
-			name := machinePoolResource["name"].(string)
-			hash := resourceMachinePoolVirtualHash(machinePoolResource)
-
-			machinePool := toMachinePoolVirtual(machinePoolResource)
-
-			var err error
-			if oldMachinePool, ok := osMap[name]; !ok {
-				log.Printf("Create machine pool %s", name)
-				err = c.CreateMachinePoolVirtual(cloudConfigId, machinePool)
-			} else if hash != resourceMachinePoolVirtualHash(oldMachinePool) {
-				log.Printf("Change in machine pool %s", name)
-				err = c.UpdateMachinePoolVirtual(cloudConfigId, machinePool)
-			}
-			if err != nil {
-				return diag.FromErr(err)
+                        // since known issue in TF SDK: https://github.com/hashicorp/terraform-plugin-sdk/issues/588
+			if machinePoolResource["name"].(string) != "" {
+				name := machinePoolResource["name"].(string)
+				hash := resourceMachinePoolVirtualHash(machinePoolResource)
+
+				machinePool := toMachinePoolVirtual(machinePoolResource)
+
+				var err error
+				if oldMachinePool, ok := osMap[name]; !ok {
+					log.Printf("Create machine pool %s", name)
+					err = c.CreateMachinePoolVirtual(cloudConfigId, machinePool)
+				} else if hash != resourceMachinePoolVirtualHash(oldMachinePool) {
+					log.Printf("Change in machine pool %s", name)
+					err = c.UpdateMachinePoolVirtual(cloudConfigId, machinePool)
+				}
+				if err != nil {
+					return diag.FromErr(err)
+				}
+
+				// Processed (if exists)
+				delete(osMap, name)
 			}
 
-			// Processed (if exists)
-			delete(osMap, name)
 		}
 
 		// Deleted old machine pools