-
Notifications
You must be signed in to change notification settings - Fork 260
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
Docs update and custom image options update #538
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -179,15 +179,28 @@ func resourceDigitalOceanCustomImageUpdate(ctx context.Context, d *schema.Resour | |||||||||||||||||||||||||||||||||||||||||
return diag.Errorf("Error converting id %s to string: %s", imageID, err) | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
if d.HasChange("name") { | ||||||||||||||||||||||||||||||||||||||||||
name := d.Get("name").(string) | ||||||||||||||||||||||||||||||||||||||||||
_, _, err := client.Images.Update(ctx, id, &godo.ImageUpdateRequest{ | ||||||||||||||||||||||||||||||||||||||||||
Name: name, | ||||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||
if d.HasChanges("name", "description", "distribution") { | ||||||||||||||||||||||||||||||||||||||||||
imageName := d.Get("name").(string) | ||||||||||||||||||||||||||||||||||||||||||
imageUpdateRequest := &godo.ImageUpdateRequest{} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
if d.HasChange("name") { | ||||||||||||||||||||||||||||||||||||||||||
imageUpdateRequest.Name = imageName | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
if d.HasChange("distribution") { | ||||||||||||||||||||||||||||||||||||||||||
imageDistribution := d.Get("distribution").(string) | ||||||||||||||||||||||||||||||||||||||||||
imageUpdateRequest.Distribution = imageDistribution | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
if d.HasChange("description") { | ||||||||||||||||||||||||||||||||||||||||||
imageDescription := d.Get("description").(string) | ||||||||||||||||||||||||||||||||||||||||||
imageUpdateRequest.Description = imageDescription | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We can simplify this a bit. PUT is idempotent, so no reason not to build the full request. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't noticed it was idempotent, was trying to change only fields that changed. I'll make this change |
||||||||||||||||||||||||||||||||||||||||||
_, _, err := client.Images.Update(ctx, id, imageUpdateRequest) | ||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||
return diag.Errorf("Error updating image %s, name %s: %s", imageID, name, err) | ||||||||||||||||||||||||||||||||||||||||||
return diag.Errorf("Error updating image %s, name %s: %s", imageID, imageName, err) | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
return resourceDigitalOceanCustomImageRead(ctx, d, meta) | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀 Hadn't noticed they've introduced
HasChanges
. Much nicer than the oldif d.HasChange("foo") || d.HasChange("bar")
syntaxt.