fix(terraform): keep prior state when /key/update is rejected

A rejected update must not persist its values into state. Without
partial mode the SDK writes the proposed config into state even when
Update returns an error, so a 400 (e.g. invalid budget_duration)
leaked the rejected values. Enable partial mode on the UpdateKey
error path, mirroring the plannedKeyMetadata error branch above it.

Fixes the 'gofmt, vet, build, test' failure in the Terraform Provider
workflow (TestResourceKeyUpdateFailureKeepsPriorState).
This commit is contained in:
Eric K. Sender 2026-09-10 08:02:01 -07:00
parent 5b394923b0
commit 09def488cd

View file

@ -327,6 +327,11 @@ func resourceKeyUpdate(ctx context.Context, d *schema.ResourceData, m interface{
key.Metadata = metadata
if _, err := c.UpdateKey(key); err != nil {
// The proxy rejected the whole update, so nothing was applied
// server-side. Keep prior state instead of persisting the
// rejected values: without partial mode the SDK writes the
// proposed config into state even when Update returns an error.
d.Partial(true)
return diag.FromErr(fmt.Errorf("error updating key: %s", err))
}