mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-04 13:17:43 -06:00
ff2de9c818
When an operation fails, providers may return a null new value rather than returning a partial state. In that case, we'd prefer to keep the old value so that we stand the best chance of being able to retry on a subsequent run. Previously we were making an exception for the delete action, allowing the result of that to be null even when an error is returned. In practice that was a bad idea because it would cause Terraform to lose track of the object even though it might not actually have been deleted. Now we'll retain the old object even in the delete case. Providers can still return partial new objects if they were able to partially complete a delete operation, in which case we'll discard what we had before, but if the result is null with errors then we'll assume the delete failed entirely and so just keep the old state as-is, giving us the opportunity to refresh it on the next run to see if anything actually happened after all. (This also includes a new resource in the test provider which isn't used by the patch but was useful for some manual UX testing here, so I thought I'd include it in case it's similarly useful in future, given how simple its implementation is.)
31 lines
794 B
Go
31 lines
794 B
Go
package test
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
)
|
|
|
|
func testResourceUndeleteable() *schema.Resource {
|
|
return &schema.Resource{
|
|
Create: testResourceUndeleteableCreate,
|
|
Read: testResourceUndeleteableRead,
|
|
Delete: testResourceUndeleteableDelete,
|
|
|
|
Schema: map[string]*schema.Schema{},
|
|
}
|
|
}
|
|
|
|
func testResourceUndeleteableCreate(d *schema.ResourceData, meta interface{}) error {
|
|
d.SetId("placeholder")
|
|
return testResourceUndeleteableRead(d, meta)
|
|
}
|
|
|
|
func testResourceUndeleteableRead(d *schema.ResourceData, meta interface{}) error {
|
|
return nil
|
|
}
|
|
|
|
func testResourceUndeleteableDelete(d *schema.ResourceData, meta interface{}) error {
|
|
return fmt.Errorf("test_undeleteable always fails deletion (use terraform state rm if you really want to delete it)")
|
|
}
|