forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete.go
36 lines (29 loc) · 1.09 KB
/
delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package helpers
import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/acceptance/types"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/clients"
)
// DeleteResourceFunc returns a TestCheckFunc which deletes the resource within Azure
// this is only used within the Internal
func DeleteResourceFunc(client *clients.Client, testResource types.TestResourceVerifyingRemoved, resourceName string) func(state *terraform.State) error {
return func(state *terraform.State) error {
ctx := client.StopContext
rs, ok := state.RootModule().Resources[resourceName]
if !ok {
return fmt.Errorf("%q was not found in the state", resourceName)
}
result, err := testResource.Destroy(ctx, client, rs.Primary)
if err != nil {
return fmt.Errorf("running destroy func for %q: %+v", resourceName, err)
}
if result == nil {
return fmt.Errorf("received nil for destroy result for %q", resourceName)
}
if !*result {
return fmt.Errorf("deleting %q but no error", resourceName)
}
return nil
}
}