-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_prevent_destroy.go
54 lines (48 loc) · 1.36 KB
/
resource_prevent_destroy.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"errors"
"log"
"math/rand"
"os"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func resourcePreventDestroy() *schema.Resource {
return &schema.Resource{
Create: resourcePreventDestroyCreate,
Read: resourcePreventDestroyRead,
Delete: resourcePreventDestroyDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"triggers": {
Type: schema.TypeMap,
ForceNew: true,
Optional: true,
},
},
}
}
func resourcePreventDestroyCreate(d *schema.ResourceData, m interface{}) error {
d.SetId(strconv.Itoa(rand.Int()))
return resourcePreventDestroyRead(d, m)
}
func resourcePreventDestroyRead(d *schema.ResourceData, m interface{}) error {
return nil
}
func resourcePreventDestroyDelete(d *schema.ResourceData, m interface{}) error {
if os.Getenv("TF_PREVENT_DESTROY") == "false" {
log.Printf("TF_PREVENT_DESTROY=false, so allowing destroy.")
return nil
}
return errors.New(
"Destroy blocked by figma_prevent_destroy." +
" This protects against accidental destruction of important resources." +
" Please check your plan and make sure you're not destroying anything important." +
" If you really must destroy, set TF_PREVENT_DESTROY=false and re-run.")
}