-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle scenarios where the dcl resource can't be found on READ (#5166)
- Loading branch information
1 parent
2f48ca5
commit 6f745ae
Showing
2 changed files
with
23 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,26 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
dcl "github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl" | ||
"github.com/hashicorp/errwrap" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func oldValue(old, new interface{}) interface{} { | ||
return old | ||
} | ||
|
||
func handleNotFoundDCLError(err error, d *schema.ResourceData, resourceName string) error { | ||
if dcl.IsNotFound(err) { | ||
log.Printf("[WARN] Removing %s because it's gone", resourceName) | ||
// The resource doesn't exist anymore | ||
d.SetId("") | ||
return nil | ||
} | ||
|
||
return errwrap.Wrapf( | ||
fmt.Sprintf("Error when reading or editing %s: {{err}}", resourceName), err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters