|
| 1 | +package tfsdk |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + "github.com/hashicorp/terraform-plugin-framework/schema" |
| 7 | + "github.com/hashicorp/terraform-plugin-go/tfprotov6" |
| 8 | +) |
| 9 | + |
| 10 | +// A ResourceType is a type of resource. For each type of resource this provider |
| 11 | +// supports, it should define a type implementing ResourceType and return an |
| 12 | +// instance of it in the map returned by Provider.GeResources. |
| 13 | +type ResourceType interface { |
| 14 | + // GetSchema returns the schema for this resource. |
| 15 | + GetSchema(context.Context) (schema.Schema, []*tfprotov6.Diagnostic) |
| 16 | + |
| 17 | + // NewResource instantiates a new Resource of this ResourceType. |
| 18 | + NewResource(Provider) (Resource, []*tfprotov6.Diagnostic) |
| 19 | +} |
| 20 | + |
| 21 | +// Resource represents a resource instance. This is the core interface that all |
| 22 | +// resources must implement. |
| 23 | +type Resource interface { |
| 24 | + // Create is called when the provider must create a new resource. Config |
| 25 | + // and planned state values should be read from the |
| 26 | + // CreateResourceRequest and new state values set on the |
| 27 | + // CreateResourceResponse. |
| 28 | + Create(context.Context, *CreateResourceRequest, *CreateResourceResponse) |
| 29 | + |
| 30 | + // Read is called when the provider must read resource values in order |
| 31 | + // to update state. Planned state values should be read from the |
| 32 | + // ReadResourceRequest and new state values set on the |
| 33 | + // ReadResourceResponse. |
| 34 | + Read(context.Context, *ReadResourceRequest, *ReadResourceResponse) |
| 35 | + |
| 36 | + // Update is called to update the state of the resource. Config, planned |
| 37 | + // state, and prior state values should be read from the |
| 38 | + // UpdateResourceRequest and new state values set on the |
| 39 | + // UpdateResourceResponse. |
| 40 | + Update(context.Context, *UpdateResourceRequest, *UpdateResourceResponse) |
| 41 | + |
| 42 | + // Delete is called when the provider must delete the resource. Config |
| 43 | + // values may be read from the DeleteResourceRequest. |
| 44 | + Delete(context.Context, *DeleteResourceRequest, *DeleteResourceResponse) |
| 45 | +} |
0 commit comments