Skip to content

Commit

Permalink
Merge pull request #110 from HewlettPackard/networkReconfig
Browse files Browse the repository at this point in the history
[DE8379] Allow primary network updation
  • Loading branch information
manjunath-batakurki authored Feb 10, 2022
2 parents e0731a4 + 79aa57a commit fdfd142
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 37 deletions.
37 changes: 1 addition & 36 deletions internal/resources/diffValidation/resource_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ package diffvalidation

import (
"fmt"
"reflect"
"strings"

"github.com/HewlettPackard/hpegl-vmaas-terraform-resources/internal/utils"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

var errPrimaryNetworkUpdation = fmt.Errorf("primary network updation/deletion is not supported")

type Instance struct {
diff *schema.ResourceDiff
}
Expand Down Expand Up @@ -51,45 +48,13 @@ func (i *Instance) DiffValidate() error {
return err
}

if err := i.validateIsPrimaryNetworkChanged(); err != nil {
return err
}

if err := i.instanceValidateSnapshotDeletion(); err != nil {
return err
}

return nil
}

func (i *Instance) validateIsPrimaryNetworkChanged() error {
if i.diff.HasChange("network") {
o, n := i.diff.GetChange("network")
oldMap := utils.GetlistMap(o)
newMap := utils.GetlistMap(n)

// skip upon create operation
if len(oldMap) == 0 {
return nil
}
// check whether primary network has been changed?
for i := range oldMap {
if oldMap[i]["is_primary"].(bool) {
if len(newMap) < i {
return errPrimaryNetworkUpdation
}
if !reflect.DeepEqual(newMap[i], oldMap[i]) {
return errPrimaryNetworkUpdation
}

break
}
}
}

return nil
}

func (i *Instance) instanceTemplateValidate() error {
configSet := i.diff.Get("config").(*schema.Set)
if configSet == nil {
Expand Down Expand Up @@ -218,7 +183,7 @@ func (i *Instance) instanceValidateSnapshotDeletion() error {
newMap := utils.GetlistMap(newSnapshotValue)
// if an attempt to delete the snapshot, then return error
if len(newMap) <= 0 {
return fmt.Errorf("Deleting snapshot is not supported currently.")
return fmt.Errorf("deleting snapshot is not supported currently")
}
return nil
}
2 changes: 1 addition & 1 deletion internal/resources/resource_instances_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func getInstanceDefaultSchema(isClone bool) *schema.Resource {
"is_primary": {
Type: schema.TypeBool,
Computed: true,
Description: `Flag to identify given network is primary or not. Primary network cannot be updated or deleted.`,
Description: `Flag to identify given network is primary or not. Primary network cannot be deleted.`,
},
"internal_id": {
Type: schema.TypeInt,
Expand Down

0 comments on commit fdfd142

Please sign in to comment.