Skip to content

Commit

Permalink
Merge pull request #257 from HewlettPackard/schema-fix
Browse files Browse the repository at this point in the history
Show errors on changing template_id and storage_type
  • Loading branch information
manjunath-batakurki authored Sep 20, 2024
2 parents 443ad2c + a3d3699 commit fc10c14
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions internal/cmp/instance_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ func instanceCompareVolumes(org, new []map[string]interface{}) ([]map[string]int
if new[i]["size"].(int) < org[j]["size"].(int) {
return nil, fmt.Errorf("storage volume %s of the instance can't be reduced", new[i]["name"])
}
if new[i]["storage_type"] != org[j]["storage_type"] {
return nil, fmt.Errorf("storage type of volume %s can't be changed", new[i]["name"])
}

break
}
Expand Down
11 changes: 10 additions & 1 deletion internal/resources/diffValidation/resource_instances.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// (C) Copyright 2021 Hewlett Packard Enterprise Development LP
// (C) Copyright 2021-2024 Hewlett Packard Enterprise Development LP

package diffvalidation

Expand Down Expand Up @@ -70,6 +70,15 @@ func (i *Instance) instanceTemplateValidate() error {
if templateID == 0 {
return fmt.Errorf("template_id is required for 'vmware' instance type code")
}
oldConfig, _ := i.diff.GetChange("config")
oldTemplateID := templateID
oldConfigList := oldConfig.(*schema.Set).List()
if len(oldConfigList) > 0 {
oldTemplateID = oldConfigList[0].(map[string]interface{})["template_id"].(int)
}
if oldTemplateID != templateID {
return fmt.Errorf("template_id of an instance can't be changed")
}
}
}

Expand Down
1 change: 0 additions & 1 deletion internal/resources/resource_instances_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ func getInstanceDefaultSchema(isClone bool) *schema.Resource {
Optional: true,
Description: `Storage type ID can be obtained from hpegl_vmaas_instance_disk_type
data source.`,
DiffSuppressFunc: utils.SkipField(),
},
"id": {
Computed: true,
Expand Down

0 comments on commit fc10c14

Please sign in to comment.