aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/terraform/terraform/eval_check_prevent_destroy.go
diff options
context:
space:
mode:
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.go41
1 files changed, 26 insertions, 15 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
index 715e79e..4dff0c8 100644
--- a/vendor/github.com/hashicorp/terraform/terraform/eval_check_prevent_destroy.go
+++ b/vendor/github.com/hashicorp/terraform/terraform/eval_check_prevent_destroy.go
@@ -3,33 +3,44 @@ package terraform
3import ( 3import (
4 "fmt" 4 "fmt"
5 5
6 "github.com/hashicorp/terraform/config" 6 "github.com/hashicorp/terraform/plans"
7
8 "github.com/hashicorp/hcl2/hcl"
9
10 "github.com/hashicorp/terraform/addrs"
11 "github.com/hashicorp/terraform/configs"
12 "github.com/hashicorp/terraform/tfdiags"
7) 13)
8 14
9// EvalPreventDestroy is an EvalNode implementation that returns an 15// EvalPreventDestroy is an EvalNode implementation that returns an
10// error if a resource has PreventDestroy configured and the diff 16// error if a resource has PreventDestroy configured and the diff
11// would destroy the resource. 17// would destroy the resource.
12type EvalCheckPreventDestroy struct { 18type EvalCheckPreventDestroy struct {
13 Resource *config.Resource 19 Addr addrs.ResourceInstance
14 ResourceId string 20 Config *configs.Resource
15 Diff **InstanceDiff 21 Change **plans.ResourceInstanceChange
16} 22}
17 23
18func (n *EvalCheckPreventDestroy) Eval(ctx EvalContext) (interface{}, error) { 24func (n *EvalCheckPreventDestroy) Eval(ctx EvalContext) (interface{}, error) {
19 if n.Diff == nil || *n.Diff == nil || n.Resource == nil { 25 if n.Change == nil || *n.Change == nil || n.Config == nil || n.Config.Managed == nil {
20 return nil, nil 26 return nil, nil
21 } 27 }
22 28
23 diff := *n.Diff 29 change := *n.Change
24 preventDestroy := n.Resource.Lifecycle.PreventDestroy 30 preventDestroy := n.Config.Managed.PreventDestroy
25 31
26 if diff.GetDestroy() && preventDestroy { 32 if (change.Action == plans.Delete || change.Action.IsReplace()) && preventDestroy {
27 resourceId := n.ResourceId 33 var diags tfdiags.Diagnostics
28 if resourceId == "" { 34 diags = diags.Append(&hcl.Diagnostic{
29 resourceId = n.Resource.Id() 35 Severity: hcl.DiagError,
30 } 36 Summary: "Instance cannot be destroyed",
31 37 Detail: fmt.Sprintf(
32 return nil, fmt.Errorf(preventDestroyErrStr, resourceId) 38 "Resource %s has lifecycle.prevent_destroy set, but the plan calls for this resource to be destroyed. To avoid this error and continue with the plan, either disable lifecycle.prevent_destroy or reduce the scope of the plan using the -target flag.",
39 n.Addr.Absolute(ctx.Path()).String(),
40 ),
41 Subject: &n.Config.DeclRange,
42 })
43 return nil, diags.Err()
33 } 44 }
34 45
35 return nil, nil 46 return nil, nil