@@ -3,6 +3,7 @@ package simple
33
44import (
55 "errors"
6+ "fmt"
67 "time"
78
89 "github.com/hashicorp/terraform/internal/configs/configschema"
@@ -42,6 +43,9 @@ func Provider() providers.Interface {
4243 DataSources : map [string ]providers.Schema {
4344 "simple_resource" : simpleResource ,
4445 },
46+ Capabilities : providers.Capabilities {
47+ PlanDestroy : true ,
48+ },
4549 },
4650 }
4751}
@@ -88,7 +92,10 @@ func (s simple) PlanResourceChange(req providers.PlanResourceChangeRequest) (res
8892 if req .ProposedNewState .IsNull () {
8993 // destroy op
9094 resp .PlannedState = req .ProposedNewState
91- resp .PlannedPrivate = req .PriorPrivate
95+
96+ // signal that this resource was properly planned for destruction,
97+ // verifying that the schema capabilities with PlanDestroy took effect.
98+ resp .PlannedPrivate = []byte ("destroy planned" )
9299 return resp
93100 }
94101
@@ -104,6 +111,11 @@ func (s simple) PlanResourceChange(req providers.PlanResourceChangeRequest) (res
104111
105112func (s simple ) ApplyResourceChange (req providers.ApplyResourceChangeRequest ) (resp providers.ApplyResourceChangeResponse ) {
106113 if req .PlannedState .IsNull () {
114+ // make sure this was transferred from the plan action
115+ if string (req .PlannedPrivate ) != "destroy planned" {
116+ resp .Diagnostics = resp .Diagnostics .Append (fmt .Errorf ("resource not planned for destroy, private data %q" , req .PlannedPrivate ))
117+ }
118+
107119 resp .NewState = req .PlannedState
108120 return resp
109121 }
0 commit comments