Skip to content

Commit

Permalink
Add check for template_id and storage_type
Browse files Browse the repository at this point in the history
  • Loading branch information
mahesh-hpe committed Sep 19, 2024
1 parent 52aca08 commit a3d3699
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 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
2 changes: 0 additions & 2 deletions 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 Expand Up @@ -203,7 +202,6 @@ func getInstanceDefaultSchema(isClone bool) *schema.Resource {
"template_id": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Description: "Unique ID for the template",
},
"no_agent": {
Expand Down

0 comments on commit a3d3699

Please sign in to comment.