Skip to content

Commit

Permalink
Merge pull request nutanix#202 from yannickstruyf3/bugfix/issue-182-s…
Browse files Browse the repository at this point in the history
…ource_path-image_type-missing

fixed source_path image_type issue
  • Loading branch information
marinsalinas authored Nov 30, 2020
2 parents c4fa2ad + bade6ce commit 897edf3
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions nutanix/resource_nutanix_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ func resourceNutanixImageRead(d *schema.ResourceData, meta interface{}) error {
if err != nil {
if strings.Contains(fmt.Sprint(err), "ENTITY_NOT_FOUND") {
d.SetId("")
return nil
}
return fmt.Errorf("error reading image UUID (%s) with error %s", uuid, err)
}
Expand Down Expand Up @@ -480,7 +481,7 @@ func resourceNutanixImageUpdate(d *schema.ResourceData, meta interface{}) error
spec.Description = utils.StringPtr(d.Get("description").(string))
}

if d.HasChange("source_uri") || d.HasChange("checksum") {
if d.HasChange("source_uri") || d.HasChange("checksum") || d.HasChange("source_path") {
if err := getImageResource(d, res); err != nil {
return err
}
Expand Down Expand Up @@ -566,9 +567,20 @@ func resourceNutanixImageDelete(d *schema.ResourceData, meta interface{}) error
func getImageResource(d *schema.ResourceData, image *v3.ImageResources) error {
cs, csok := d.GetOk("checksum")
checks := &v3.Checksum{}

if su, suok := d.GetOk("source_uri"); suok {
switch ext := filepath.Ext(su.(string)); ext {
su, suok := d.GetOk("source_uri")
sp, spok := d.GetOk("source_path")
var furi string
if suok {
image.SourceURI = utils.StringPtr(su.(string))
furi = su.(string)
}
if spok {
furi = sp.(string)
}
if it, itok := d.GetOk("image_type"); itok {
image.ImageType = utils.StringPtr(it.(string))
} else {
switch ext := filepath.Ext(furi); ext {
case ".qcow2":
image.ImageType = utils.StringPtr("DISK_IMAGE")
case ".iso":
Expand All @@ -578,7 +590,6 @@ func getImageResource(d *schema.ResourceData, image *v3.ImageResources) error {
image.ImageType = utils.StringPtr("DISK_IMAGE")
}
// set source uri
image.SourceURI = utils.StringPtr(su.(string))
}

if csok {
Expand Down

0 comments on commit 897edf3

Please sign in to comment.