Skip to content

Commit

Permalink
PLT-536:Added fix for machine pool type set empty item issue (#306)
Browse files Browse the repository at this point in the history
* PLT-536:Added fix for machine pool type set empty item issue

* Update spectrocloud/resource_cluster_aks.go

Co-authored-by: nikchern <[email protected]>

* 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 <[email protected]>
  • Loading branch information
SivaanandM and nikchern authored Jun 30, 2023
1 parent 5a02510 commit 278ce01
Show file tree
Hide file tree
Showing 12 changed files with 269 additions and 231 deletions.
35 changes: 19 additions & 16 deletions spectrocloud/resource_cluster_aks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 23 additions & 20 deletions spectrocloud/resource_cluster_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
41 changes: 22 additions & 19 deletions spectrocloud/resource_cluster_azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 22 additions & 19 deletions spectrocloud/resource_cluster_coxedge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 25 additions & 22 deletions spectrocloud/resource_cluster_edge_native.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 26 additions & 23 deletions spectrocloud/resource_cluster_edge_vsphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
41 changes: 22 additions & 19 deletions spectrocloud/resource_cluster_eks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 278ce01

Please sign in to comment.