Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Commit

Permalink
storagezone: use d.Partial in Update instead of revertUpdateValues
Browse files Browse the repository at this point in the history
That after a failed update changes to the resource are still applied is a know
bug (hashicorp/terraform-plugin-sdk#476).
It affects attributes that are not retrieved via the Get function and set only
by the provider.
custom_404_file_path is such a field.
As workaround d.Partial() can be called.
This is more simple then the revertUpdateValues() implementation.
  • Loading branch information
fho committed Jun 16, 2022
1 parent 705733b commit faedc93
Showing 1 changed file with 5 additions and 25 deletions.
30 changes: 5 additions & 25 deletions internal/provider/resource_storagezone.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,11 @@ func resourceStorageZoneUpdate(ctx context.Context, d *schema.ResourceData, meta

updateErr := clt.StorageZone.Update(ctx, id, storageZone)
if updateErr != nil {
// if our update failed then revert our values to their original
// state so that we can run an apply again.
revertErr := revertUpdateValues(d)

if revertErr != nil {
return diagsErrFromErr("updating storage zone via API failed", revertErr)
}

// The storagezone contains fields /custom_404_file_path) that are only updated by the
// provider and not retrieved via ReadContext(). This causes that we run into the bug
// https://github.com/hashicorp/terraform-plugin-sdk/issues/476.
// As workaround d.Partial(true) is called.
d.Partial(true)
return diagsErrFromErr("updating storage zone via API failed", updateErr)
}

Expand Down Expand Up @@ -370,23 +367,6 @@ func storageZoneToResource(sz *bunny.StorageZone, d *schema.ResourceData) error
return nil
}

func revertUpdateValues(d *schema.ResourceData) error {
o, _ := d.GetChange(keyOriginURL)
if err := d.Set(keyOriginURL, o); err != nil {
return err
}
o, _ = d.GetChange(keyCustom404FilePath)
if err := d.Set(keyCustom404FilePath, o); err != nil {
return err
}
o, _ = d.GetChange(keyRewrite404To200)
if err := d.Set(keyRewrite404To200, o); err != nil {
return err
}

return nil
}

// storageZoneFromResource returns a StorageZoneUpdateOptions API type that
// has fields set to the values in d.
func storageZoneFromResource(d *schema.ResourceData) *bunny.StorageZoneUpdateOptions {
Expand Down

0 comments on commit faedc93

Please sign in to comment.