@@ -13,6 +13,8 @@ import (
13
13
hclog "github.com/hashicorp/go-hclog"
14
14
"github.com/hashicorp/terraform-plugin-framework/diag"
15
15
"github.com/hashicorp/terraform-plugin-framework/path"
16
+ "github.com/hashicorp/terraform-plugin-framework/provider"
17
+ "github.com/hashicorp/terraform-plugin-framework/resource"
16
18
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
17
19
"github.com/hashicorp/terraform-plugin-log/tflog"
18
20
tfcloudcontrol "github.com/hashicorp/terraform-provider-awscc/internal/service/cloudcontrol"
@@ -22,14 +24,14 @@ import (
22
24
)
23
25
24
26
// ResourceTypeOptionsFunc is a type alias for a resource type functional option.
25
- type ResourceTypeOptionsFunc func (* resourceType ) error
27
+ type ResourceTypeOptionsFunc func (* genericResourceType ) error
26
28
27
29
// resourceWithAttributeNameMap is a helper function to construct functional options
28
30
// that set a resource type's attribute name maps.
29
31
// If multiple resourceWithAttributeNameMap calls are made, the last call overrides
30
32
// the previous calls' values.
31
33
func resourceWithAttributeNameMap (v map [string ]string ) ResourceTypeOptionsFunc {
32
- return func (o * resourceType ) error {
34
+ return func (o * genericResourceType ) error {
33
35
if _ , ok := v ["id" ]; ! ok {
34
36
// Synthesize a mapping for the reserved top-level "id" attribute.
35
37
v ["id" ] = "ID"
@@ -57,7 +59,7 @@ func resourceWithAttributeNameMap(v map[string]string) ResourceTypeOptionsFunc {
57
59
// If multiple resourceWithCloudFormationTypeName calls are made, the last call overrides
58
60
// the previous calls' values.
59
61
func resourceWithCloudFormationTypeName (v string ) ResourceTypeOptionsFunc {
60
- return func (o * resourceType ) error {
62
+ return func (o * genericResourceType ) error {
61
63
o .cfTypeName = v
62
64
63
65
return nil
@@ -69,7 +71,7 @@ func resourceWithCloudFormationTypeName(v string) ResourceTypeOptionsFunc {
69
71
// If multiple resourceWithTerraformSchema calls are made, the last call overrides
70
72
// the previous calls' values.
71
73
func resourceWithTerraformSchema (v tfsdk.Schema ) ResourceTypeOptionsFunc {
72
- return func (o * resourceType ) error {
74
+ return func (o * genericResourceType ) error {
73
75
o .tfSchema = v
74
76
75
77
return nil
@@ -81,7 +83,7 @@ func resourceWithTerraformSchema(v tfsdk.Schema) ResourceTypeOptionsFunc {
81
83
// If multiple resourceWithTerraformTypeName calls are made, the last call overrides
82
84
// the previous calls' values.
83
85
func resourceWithTerraformTypeName (v string ) ResourceTypeOptionsFunc {
84
- return func (o * resourceType ) error {
86
+ return func (o * genericResourceType ) error {
85
87
o .tfTypeName = v
86
88
87
89
return nil
@@ -93,7 +95,7 @@ func resourceWithTerraformTypeName(v string) ResourceTypeOptionsFunc {
93
95
// If multiple resourceIsImmutableType calls are made, the last call overrides
94
96
// the previous calls' values.
95
97
func resourceIsImmutableType (v bool ) ResourceTypeOptionsFunc {
96
- return func (o * resourceType ) error {
98
+ return func (o * genericResourceType ) error {
97
99
o .isImmutableType = v
98
100
99
101
return nil
@@ -105,7 +107,7 @@ func resourceIsImmutableType(v bool) ResourceTypeOptionsFunc {
105
107
// If multiple resourceWithSyntheticIDAttribute calls are made, the last call overrides
106
108
// the previous calls' values.
107
109
func resourceWithSyntheticIDAttribute (v bool ) ResourceTypeOptionsFunc {
108
- return func (o * resourceType ) error {
110
+ return func (o * genericResourceType ) error {
109
111
o .syntheticIDAttribute = v
110
112
111
113
return nil
@@ -117,7 +119,7 @@ func resourceWithSyntheticIDAttribute(v bool) ResourceTypeOptionsFunc {
117
119
// If multiple resourceWithWriteOnlyPropertyPaths calls are made, the last call overrides
118
120
// the previous calls' values.
119
121
func resourceWithWriteOnlyPropertyPaths (v []string ) ResourceTypeOptionsFunc {
120
- return func (o * resourceType ) error {
122
+ return func (o * genericResourceType ) error {
121
123
writeOnlyAttributePaths := make ([]* path.Path , 0 )
122
124
123
125
for _ , writeOnlyPropertyPath := range v {
@@ -147,7 +149,7 @@ const (
147
149
// If multiple resourceWithCreateTimeoutInMinutes calls are made, the last call overrides
148
150
// the previous calls' values.
149
151
func resourceWithCreateTimeoutInMinutes (v int ) ResourceTypeOptionsFunc {
150
- return func (o * resourceType ) error {
152
+ return func (o * genericResourceType ) error {
151
153
if v > 0 {
152
154
o .createTimeout = time .Duration (v ) * time .Minute
153
155
} else {
@@ -163,7 +165,7 @@ func resourceWithCreateTimeoutInMinutes(v int) ResourceTypeOptionsFunc {
163
165
// If multiple resourceWithUpdateTimeoutInMinutes calls are made, the last call overrides
164
166
// the previous calls' values.
165
167
func resourceWithUpdateTimeoutInMinutes (v int ) ResourceTypeOptionsFunc {
166
- return func (o * resourceType ) error {
168
+ return func (o * genericResourceType ) error {
167
169
if v > 0 {
168
170
o .updateTimeout = time .Duration (v ) * time .Minute
169
171
} else {
@@ -179,7 +181,7 @@ func resourceWithUpdateTimeoutInMinutes(v int) ResourceTypeOptionsFunc {
179
181
// If multiple resourceWithDeleteTimeoutInMinutes calls are made, the last call overrides
180
182
// the previous calls' values.
181
183
func resourceWithDeleteTimeoutInMinutes (v int ) ResourceTypeOptionsFunc {
182
- return func (o * resourceType ) error {
184
+ return func (o * genericResourceType ) error {
183
185
if v > 0 {
184
186
o .deleteTimeout = time .Duration (v ) * time .Minute
185
187
} else {
@@ -195,7 +197,7 @@ func resourceWithDeleteTimeoutInMinutes(v int) ResourceTypeOptionsFunc {
195
197
// If multiple resourceWithRequiredAttributesValidators calls are made, the last call overrides
196
198
// the previous calls' values.
197
199
func resourceWithRequiredAttributesValidators (fs ... validate.RequiredAttributesFunc ) ResourceTypeOptionsFunc {
198
- return func (o * resourceType ) error {
200
+ return func (o * genericResourceType ) error {
199
201
o .requiredAttributesValidators = fs
200
202
201
203
return nil
@@ -293,8 +295,8 @@ func (opts ResourceTypeOptions) WithRequiredAttributesValidators(v ...validate.R
293
295
return append (opts , resourceWithRequiredAttributesValidators (v ... ))
294
296
}
295
297
296
- // resourceType implements tfsdk .ResourceType.
297
- type resourceType struct {
298
+ // genericResourceType implements provider .ResourceType.
299
+ type genericResourceType struct {
298
300
cfTypeName string // CloudFormation type name for the resource type
299
301
tfSchema tfsdk.Schema // Terraform schema for the resource type
300
302
tfTypeName string // Terraform type name for resource type
@@ -311,8 +313,8 @@ type resourceType struct {
311
313
312
314
// NewResourceType returns a new ResourceType from the specified varidaic list of functional options.
313
315
// It's public as it's called from generated code.
314
- func NewResourceType (_ context.Context , optFns ... ResourceTypeOptionsFunc ) (tfsdk .ResourceType , error ) {
315
- resourceType := & resourceType {}
316
+ func NewResourceType (_ context.Context , optFns ... ResourceTypeOptionsFunc ) (provider .ResourceType , error ) {
317
+ resourceType := & genericResourceType {}
316
318
317
319
for _ , optFn := range optFns {
318
320
err := optFn (resourceType )
@@ -332,16 +334,16 @@ func NewResourceType(_ context.Context, optFns ...ResourceTypeOptionsFunc) (tfsd
332
334
return resourceType , nil
333
335
}
334
336
335
- func (rt * resourceType ) GetSchema (ctx context.Context ) (tfsdk.Schema , diag.Diagnostics ) {
337
+ func (rt * genericResourceType ) GetSchema (ctx context.Context ) (tfsdk.Schema , diag.Diagnostics ) {
336
338
return rt .tfSchema , nil
337
339
}
338
340
339
- func (rt * resourceType ) NewResource (ctx context.Context , provider tfsdk .Provider ) (tfsdk .Resource , diag.Diagnostics ) {
341
+ func (rt * genericResourceType ) NewResource (ctx context.Context , provider provider .Provider ) (resource .Resource , diag.Diagnostics ) {
340
342
return newGenericResource (provider , rt ), nil
341
343
}
342
344
343
345
// propertyPathToAttributePath returns the AttributePath for the specified JSON Pointer property path.
344
- func (rt * resourceType ) propertyPathToAttributePath (propertyPath string ) (* path.Path , error ) {
346
+ func (rt * genericResourceType ) propertyPathToAttributePath (propertyPath string ) (* path.Path , error ) {
345
347
segments := strings .Split (propertyPath , "/" )
346
348
347
349
if got , expected := len (segments ), 3 ; got < expected {
@@ -375,14 +377,14 @@ func (rt *resourceType) propertyPathToAttributePath(propertyPath string) (*path.
375
377
return & attributePath , nil
376
378
}
377
379
378
- // Implements tfsdk .Resource.
379
- type resource struct {
380
+ // Implements genericResource .Resource.
381
+ type genericResource struct {
380
382
provider tfcloudcontrol.Provider
381
- resourceType * resourceType
383
+ resourceType * genericResourceType
382
384
}
383
385
384
- func newGenericResource (provider tfsdk .Provider , resourceType * resourceType ) tfsdk .Resource {
385
- return & resource {
386
+ func newGenericResource (provider provider .Provider , resourceType * genericResourceType ) resource .Resource {
387
+ return & genericResource {
386
388
provider : provider .(tfcloudcontrol.Provider ),
387
389
resourceType : resourceType ,
388
390
}
@@ -394,7 +396,7 @@ var (
394
396
idAttributePath = path .Root ("id" )
395
397
)
396
398
397
- func (r * resource ) Create (ctx context.Context , request tfsdk. CreateResourceRequest , response * tfsdk. CreateResourceResponse ) {
399
+ func (r * genericResource ) Create (ctx context.Context , request resource. CreateRequest , response * resource. CreateResponse ) {
398
400
ctx = r .cfnTypeContext (ctx )
399
401
400
402
traceEntry (ctx , "Resource.Create" )
@@ -495,7 +497,7 @@ func (r *resource) Create(ctx context.Context, request tfsdk.CreateResourceReque
495
497
traceExit (ctx , "Resource.Create" )
496
498
}
497
499
498
- func (r * resource ) Read (ctx context.Context , request tfsdk. ReadResourceRequest , response * tfsdk. ReadResourceResponse ) {
500
+ func (r * genericResource ) Read (ctx context.Context , request resource. ReadRequest , response * resource. ReadResponse ) {
499
501
ctx = r .cfnTypeContext (ctx )
500
502
501
503
traceEntry (ctx , "Resource.Read" )
@@ -581,7 +583,7 @@ func (r *resource) Read(ctx context.Context, request tfsdk.ReadResourceRequest,
581
583
traceExit (ctx , "Resource.Read" )
582
584
}
583
585
584
- func (r * resource ) Update (ctx context.Context , request tfsdk. UpdateResourceRequest , response * tfsdk. UpdateResourceResponse ) {
586
+ func (r * genericResource ) Update (ctx context.Context , request resource. UpdateRequest , response * resource. UpdateResponse ) {
585
587
ctx = r .cfnTypeContext (ctx )
586
588
587
589
traceEntry (ctx , "Resource.Update" )
@@ -680,7 +682,7 @@ func (r *resource) Update(ctx context.Context, request tfsdk.UpdateResourceReque
680
682
traceExit (ctx , "Resource.Update" )
681
683
}
682
684
683
- func (r * resource ) Delete (ctx context.Context , request tfsdk. DeleteResourceRequest , response * tfsdk. DeleteResourceResponse ) {
685
+ func (r * genericResource ) Delete (ctx context.Context , request resource. DeleteRequest , response * resource. DeleteResponse ) {
684
686
ctx = r .cfnTypeContext (ctx )
685
687
686
688
traceEntry (ctx , "Resource.Delete" )
@@ -708,7 +710,7 @@ func (r *resource) Delete(ctx context.Context, request tfsdk.DeleteResourceReque
708
710
traceExit (ctx , "Resource.Delete" )
709
711
}
710
712
711
- func (r * resource ) ImportState (ctx context.Context , request tfsdk. ImportResourceStateRequest , response * tfsdk. ImportResourceStateResponse ) {
713
+ func (r * genericResource ) ImportState (ctx context.Context , request resource. ImportStateRequest , response * resource. ImportStateResponse ) {
712
714
ctx = r .cfnTypeContext (ctx )
713
715
714
716
traceEntry (ctx , "Resource.ImportState" )
@@ -717,14 +719,14 @@ func (r *resource) ImportState(ctx context.Context, request tfsdk.ImportResource
717
719
"value" : hclog .Fmt ("%v" , request .ID ),
718
720
})
719
721
720
- tfsdk . ResourceImportStatePassthroughID (ctx , idAttributePath , request , response )
722
+ resource . ImportStatePassthroughID (ctx , idAttributePath , request , response )
721
723
722
724
traceExit (ctx , "Resource.ImportState" )
723
725
}
724
726
725
727
// ConfigValidators returns a list of functions which will all be performed during validation.
726
- func (r * resource ) ConfigValidators (context.Context ) []tfsdk. ResourceConfigValidator {
727
- validators := make ([]tfsdk. ResourceConfigValidator , 0 )
728
+ func (r * genericResource ) ConfigValidators (context.Context ) []resource. ConfigValidator {
729
+ validators := make ([]resource. ConfigValidator , 0 )
728
730
729
731
if len (r .resourceType .requiredAttributesValidators ) > 0 {
730
732
validators = append (validators , validate .ResourceConfigRequiredAttributes (r .resourceType .requiredAttributesValidators ... ))
@@ -734,12 +736,12 @@ func (r *resource) ConfigValidators(context.Context) []tfsdk.ResourceConfigValid
734
736
}
735
737
736
738
// describe returns the live state of the specified resource.
737
- func (r * resource ) describe (ctx context.Context , conn * cloudcontrol.Client , id string ) (* cctypes.ResourceDescription , error ) {
739
+ func (r * genericResource ) describe (ctx context.Context , conn * cloudcontrol.Client , id string ) (* cctypes.ResourceDescription , error ) {
738
740
return tfcloudcontrol .FindResourceByTypeNameAndID (ctx , conn , r .provider .RoleARN (ctx ), r .resourceType .cfTypeName , id )
739
741
}
740
742
741
743
// getId returns the resource's primary identifier value from State.
742
- func (r * resource ) getId (ctx context.Context , state * tfsdk.State ) (string , error ) {
744
+ func (r * genericResource ) getId (ctx context.Context , state * tfsdk.State ) (string , error ) {
743
745
var val string
744
746
diags := state .GetAttribute (ctx , idAttributePath , & val )
745
747
@@ -751,7 +753,7 @@ func (r *resource) getId(ctx context.Context, state *tfsdk.State) (string, error
751
753
}
752
754
753
755
// setId sets the resource's primary identifier value in State.
754
- func (r * resource ) setId (ctx context.Context , val string , state * tfsdk.State ) error {
756
+ func (r * genericResource ) setId (ctx context.Context , val string , state * tfsdk.State ) error {
755
757
diags := state .SetAttribute (ctx , idAttributePath , val )
756
758
757
759
if diags .HasError () {
@@ -762,7 +764,7 @@ func (r *resource) setId(ctx context.Context, val string, state *tfsdk.State) er
762
764
}
763
765
764
766
// populateUnknownValues populates and unknown values in State with values from the current resource description.
765
- func (r * resource ) populateUnknownValues (ctx context.Context , id string , state * tfsdk.State ) diag.Diagnostics {
767
+ func (r * genericResource ) populateUnknownValues (ctx context.Context , id string , state * tfsdk.State ) diag.Diagnostics {
766
768
var diags diag.Diagnostics
767
769
768
770
unknowns , err := UnknownValuePaths (ctx , state .Raw )
@@ -815,7 +817,7 @@ func (r *resource) populateUnknownValues(ctx context.Context, id string, state *
815
817
}
816
818
817
819
// cfnTypeContext injects the CloudFormation type name into logger contexts.
818
- func (r * resource ) cfnTypeContext (ctx context.Context ) context.Context {
820
+ func (r * genericResource ) cfnTypeContext (ctx context.Context ) context.Context {
819
821
ctx = tflog .SetField (ctx , LoggingKeyCFNType , r .resourceType .cfTypeName )
820
822
821
823
return ctx
0 commit comments