@@ -103,11 +103,20 @@ type Resource struct {
103103 Read ReadFunc
104104 Update UpdateFunc
105105 Delete DeleteFunc
106+
107+ // Exists is a function that is called to check if a resource still
108+ // exists. If this returns false, then this will affect the diff
109+ // accordingly. If this function isn't set, it will not be called. You
110+ // can also signal existence in the Read method by calling d.SetId("")
111+ // if the Resource is no longer present and should be removed from state.
112+ // The *ResourceData passed to Exists should _not_ be modified.
113+ //
114+ // Deprecated: ReadContext should be able to encapsulate the logic of Exists
106115 Exists ExistsFunc
107116
108117 // The functions below are the CRUD operations for this resource.
109118 //
110- // The only optional operation is Update and Exists . If Update is not
119+ // The only optional operation is Update. If Update is not
111120 // implemented, then updates will not be supported for this resource.
112121 //
113122 // The ResourceData parameter in the functions below are used to
@@ -120,20 +129,11 @@ type Resource struct {
120129 // to store API clients, configuration structures, etc.
121130 //
122131 // If any errors occur during each of the operation, an error should be
123- // returned. If a resource was partially updated, be careful to enable
124- // partial state mode for ResourceData and use it accordingly.
125- //
126- // Exists is a function that is called to check if a resource still
127- // exists. If this returns false, then this will affect the diff
128- // accordingly. If this function isn't set, it will not be called. You
129- // can also signal existence in the Read method by calling d.SetId("")
130- // if the Resource is no longer present and should be removed from state.
131- // The *ResourceData passed to Exists should _not_ be modified.
132+ // returned.
132133 CreateContext CreateContextFunc
133134 ReadContext ReadContextFunc
134135 UpdateContext UpdateContextFunc
135136 DeleteContext DeleteContextFunc
136- ExistsContext ExistsContextFunc
137137
138138 // CustomizeDiff is a custom function for working with the diff that
139139 // Terraform has created for this resource - it can be used to customize the
@@ -233,9 +233,6 @@ type UpdateContextFunc func(context.Context, *ResourceData, interface{}) error
233233// See Resource documentation.
234234type DeleteContextFunc func (context.Context , * ResourceData , interface {}) error
235235
236- // See Resource documentation.
237- type ExistsContextFunc func (context.Context , * ResourceData , interface {}) (bool , error )
238-
239236// See Resource documentation.
240237type StateMigrateFunc func (
241238 int , * terraform.InstanceState , interface {}) (* terraform.InstanceState , error )
@@ -300,15 +297,6 @@ func (r *Resource) delete(ctx context.Context, d *ResourceData, meta interface{}
300297 return r .DeleteContext (ctx , d , meta )
301298}
302299
303- func (r * Resource ) exists (ctx context.Context , d * ResourceData , meta interface {}) (bool , error ) {
304- if r .Exists != nil {
305- return r .Exists (d , meta )
306- }
307- ctx , cancel := context .WithTimeout (ctx , d .Timeout (TimeoutRead ))
308- defer cancel ()
309- return r .ExistsContext (ctx , d , meta )
310- }
311-
312300// Apply creates, updates, and/or deletes a resource.
313301func (r * Resource ) Apply (
314302 ctx context.Context ,
@@ -505,7 +493,7 @@ func (r *Resource) RefreshWithoutUpgrade(
505493 }
506494 }
507495
508- if r .existsFuncSet () {
496+ if r .Exists != nil {
509497 // Make a copy of data so that if it is modified it doesn't
510498 // affect our Read later.
511499 data , err := schemaMap (r .Schema ).Data (s , nil )
@@ -515,7 +503,7 @@ func (r *Resource) RefreshWithoutUpgrade(
515503 return s , err
516504 }
517505
518- exists , err := r .exists ( ctx , data , meta )
506+ exists , err := r .Exists ( data , meta )
519507
520508 if err != nil {
521509 return s , err
@@ -557,10 +545,6 @@ func (r *Resource) deleteFuncSet() bool {
557545 return (r .Delete != nil || r .DeleteContext != nil )
558546}
559547
560- func (r * Resource ) existsFuncSet () bool {
561- return (r .Exists != nil || r .ExistsContext != nil )
562- }
563-
564548// InternalValidate should be called to validate the structure
565549// of the resource.
566550//
@@ -688,8 +672,25 @@ func (r *Resource) InternalValidate(topSchemaMap schemaMap, writable bool) error
688672 if r .DeleteContext != nil && r .Delete != nil {
689673 return fmt .Errorf ("DeleteContext and Delete should not both be set" )
690674 }
691- if r .ExistsContext != nil && r .Exists != nil {
692- return fmt .Errorf ("ExistsContext and Exists should not both be set" )
675+
676+ // Warn of deprecations
677+ if r .Exists != nil {
678+ log .Printf ("[WARN] Exists is deprecated, please encapsulate the logic in ReadContext" )
679+ }
680+ if r .Create != nil && r .CreateContext == nil {
681+ log .Printf ("[WARN] Create is deprecated, please use CreateContext" )
682+ }
683+ if r .Read != nil && r .ReadContext == nil {
684+ log .Printf ("[WARN] Read is deprecated, please use ReadContext" )
685+ }
686+ if r .Update != nil && r .UpdateContext == nil {
687+ log .Printf ("[WARN] Update is deprecated, please use UpdateContext" )
688+ }
689+ if r .Delete != nil && r .DeleteContext == nil {
690+ log .Printf ("[WARN] Delete is deprecated, please use DeleteContext" )
691+ }
692+ if r .MigrateState != nil {
693+ log .Printf ("[WARN] MigrateState is deprecated, please use StateUpgraders" )
693694 }
694695
695696 return schemaMap (r .Schema ).InternalValidate (tsm )
0 commit comments