diff options
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/terraform/eval_check_prevent_destroy.go')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/terraform/eval_check_prevent_destroy.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/terraform/terraform/eval_check_prevent_destroy.go b/vendor/github.com/hashicorp/terraform/terraform/eval_check_prevent_destroy.go new file mode 100644 index 0000000..715e79e --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/terraform/eval_check_prevent_destroy.go | |||
@@ -0,0 +1,38 @@ | |||
1 | package terraform | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | |||
6 | "github.com/hashicorp/terraform/config" | ||
7 | ) | ||
8 | |||
9 | // EvalPreventDestroy is an EvalNode implementation that returns an | ||
10 | // error if a resource has PreventDestroy configured and the diff | ||
11 | // would destroy the resource. | ||
12 | type EvalCheckPreventDestroy struct { | ||
13 | Resource *config.Resource | ||
14 | ResourceId string | ||
15 | Diff **InstanceDiff | ||
16 | } | ||
17 | |||
18 | func (n *EvalCheckPreventDestroy) Eval(ctx EvalContext) (interface{}, error) { | ||
19 | if n.Diff == nil || *n.Diff == nil || n.Resource == nil { | ||
20 | return nil, nil | ||
21 | } | ||
22 | |||
23 | diff := *n.Diff | ||
24 | preventDestroy := n.Resource.Lifecycle.PreventDestroy | ||
25 | |||
26 | if diff.GetDestroy() && preventDestroy { | ||
27 | resourceId := n.ResourceId | ||
28 | if resourceId == "" { | ||
29 | resourceId = n.Resource.Id() | ||
30 | } | ||
31 | |||
32 | return nil, fmt.Errorf(preventDestroyErrStr, resourceId) | ||
33 | } | ||
34 | |||
35 | return nil, nil | ||
36 | } | ||
37 | |||
38 | const preventDestroyErrStr = `%s: the plan would destroy this resource, but it currently has lifecycle.prevent_destroy set to true. To avoid this error and continue with the plan, either disable lifecycle.prevent_destroy or adjust the scope of the plan using the -target flag.` | ||