]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blobdiff - vendor/github.com/hashicorp/terraform/terraform/eval_check_prevent_destroy.go
Upgrade to 0.12
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / terraform / terraform / eval_check_prevent_destroy.go
index 715e79e1744de118cf26e2f8187fa68692d4b866..4dff0c84d1931d6daac704a4c8399ccadb35e308 100644 (file)
@@ -3,33 +3,44 @@ package terraform
 import (
        "fmt"
 
-       "github.com/hashicorp/terraform/config"
+       "github.com/hashicorp/terraform/plans"
+
+       "github.com/hashicorp/hcl2/hcl"
+
+       "github.com/hashicorp/terraform/addrs"
+       "github.com/hashicorp/terraform/configs"
+       "github.com/hashicorp/terraform/tfdiags"
 )
 
 // EvalPreventDestroy is an EvalNode implementation that returns an
 // error if a resource has PreventDestroy configured and the diff
 // would destroy the resource.
 type EvalCheckPreventDestroy struct {
-       Resource   *config.Resource
-       ResourceId string
-       Diff       **InstanceDiff
+       Addr   addrs.ResourceInstance
+       Config *configs.Resource
+       Change **plans.ResourceInstanceChange
 }
 
 func (n *EvalCheckPreventDestroy) Eval(ctx EvalContext) (interface{}, error) {
-       if n.Diff == nil || *n.Diff == nil || n.Resource == nil {
+       if n.Change == nil || *n.Change == nil || n.Config == nil || n.Config.Managed == nil {
                return nil, nil
        }
 
-       diff := *n.Diff
-       preventDestroy := n.Resource.Lifecycle.PreventDestroy
-
-       if diff.GetDestroy() && preventDestroy {
-               resourceId := n.ResourceId
-               if resourceId == "" {
-                       resourceId = n.Resource.Id()
-               }
-
-               return nil, fmt.Errorf(preventDestroyErrStr, resourceId)
+       change := *n.Change
+       preventDestroy := n.Config.Managed.PreventDestroy
+
+       if (change.Action == plans.Delete || change.Action.IsReplace()) && preventDestroy {
+               var diags tfdiags.Diagnostics
+               diags = diags.Append(&hcl.Diagnostic{
+                       Severity: hcl.DiagError,
+                       Summary:  "Instance cannot be destroyed",
+                       Detail: fmt.Sprintf(
+                               "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.",
+                               n.Addr.Absolute(ctx.Path()).String(),
+                       ),
+                       Subject: &n.Config.DeclRange,
+               })
+               return nil, diags.Err()
        }
 
        return nil, nil