Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed source_path image_type issue #202

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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