Skip to content

Commit

Permalink
B-552: Fix compatible_system_datastore parsing (#576)
Browse files Browse the repository at this point in the history
  • Loading branch information
sk4zuzu authored Oct 21, 2024
1 parent 26335f4 commit 51e0840
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ BUG FIXES:

* resources/opennebula_vm_group: fix anti affinity reading (#497)
* resources/opennebula_datastore: remove DS_MAD for Ceph SYSTEM datastore (#542)
* resources/opennebula_datastore: fix compatible_system_datastore parsing (#552)

# 1.4.1 (Unreleased)

Expand Down
41 changes: 33 additions & 8 deletions opennebula/resource_opennebula_datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func resourceOpennebulaDatastore() *schema.Resource {
Optional: true,
Description: "For Image Datastores only. Set the System Datastores IDs that can be used with an Image Datastore",
Elem: &schema.Schema{
Type: schema.TypeInt,
Type: schema.TypeString,
},
},
"ceph": {
Expand Down Expand Up @@ -282,13 +282,20 @@ func resourceOpennebulaDatastoreCreate(ctx context.Context, d *schema.ResourceDa

compatibleSystemDatastores := d.Get("compatible_system_datastore").(*schema.Set).List()
if len(compatibleSystemDatastores) > 0 {

// convert to slice of strings then join
var compatibleSysDs []string
for _, sysDs := range compatibleSystemDatastores {
compatibleSysDs = append(compatibleSysDs, fmt.Sprint(sysDs.(int)))
i, err := ParseIntFromInterface(sysDs)
if err != nil {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: "Failed to parse datastore ID",
Detail: err.Error(),
})
return diags
}
compatibleSysDs = append(compatibleSysDs, fmt.Sprint(i))
}

tpl.Add(dsKey.CompatibleSysDs, strings.Join(compatibleSysDs, ","))
}

Expand Down Expand Up @@ -542,7 +549,7 @@ func resourceOpennebulaDatastoreRead(ctx context.Context, d *schema.ResourceData

compatibleSystemDatastore, err := datastoreInfos.Template.Get(dsKey.CompatibleSysDs)
if err == nil {
d.Set("compatible_system_datastore", compatibleSystemDatastore)
d.Set("compatible_system_datastore", strings.Split(compatibleSystemDatastore, ","))
}

customAttrsList := d.Get("custom").(*schema.Set).List()
Expand Down Expand Up @@ -788,9 +795,27 @@ func resourceOpennebulaDatastoreUpdate(ctx context.Context, d *schema.ResourceDa
update = true
}
if d.HasChange("compatible_system_datastore") {
compatibleSystemDS := d.Get("compatible_system_datastore")
newTpl.Del(string(dsKey.CompatibleSysDs))
newTpl.Add(dsKey.CompatibleSysDs, compatibleSystemDS)
compatibleSystemDatastores := d.Get("compatible_system_datastore").(*schema.Set).List()
if len(compatibleSystemDatastores) > 0 {
// convert to slice of strings then join
var compatibleSysDs []string
for _, sysDs := range compatibleSystemDatastores {
i, err := ParseIntFromInterface(sysDs)
if err != nil {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: "Failed to parse datastore ID",
Detail: err.Error(),
})
return diags
}
compatibleSysDs = append(compatibleSysDs, fmt.Sprint(i))
}
newTpl.Del(string(dsKey.CompatibleSysDs))
newTpl.Add(dsKey.CompatibleSysDs, strings.Join(compatibleSysDs, ","))
} else {
newTpl.Del(string(dsKey.CompatibleSysDs))
}
update = true
}

Expand Down

0 comments on commit 51e0840

Please sign in to comment.