Skip to content

Commit

Permalink
refactor(fw): terraform-plugin-framework-timeouts v0.3.0 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jar-b committed Jan 3, 2023
1 parent f9e8b06 commit 4eb52d3
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions internal/service/resourceexplorer2/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/resourceexplorer2"
awstypes "github.com/aws/aws-sdk-go-v2/service/resourceexplorer2/types"
"github.com/hashicorp/terraform-plugin-framework-timeouts/timeouts"
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
Expand Down Expand Up @@ -89,8 +89,13 @@ func (r *resourceIndex) Create(ctx context.Context, request resource.CreateReque
return
}

createTimeout, d := data.Timeouts.Create(ctx, r.defaultCreateTimeout)
response.Diagnostics.Append(d...)
if response.Diagnostics.HasError() {
return
}

conn := r.Meta().ResourceExplorer2Client()
createTimeout := timeouts.Create(ctx, data.Timeouts, r.defaultCreateTimeout)
defaultTagsConfig := r.Meta().DefaultTagsConfig
ignoreTagsConfig := r.Meta().IgnoreTagsConfig
tags := defaultTagsConfig.MergeTags(tftags.New(data.Tags))
Expand Down Expand Up @@ -206,8 +211,13 @@ func (r *resourceIndex) Update(ctx context.Context, request resource.UpdateReque
return
}

updateTimeout, d := new.Timeouts.Update(ctx, r.defaultUpdateTimeout)
response.Diagnostics.Append(d...)
if response.Diagnostics.HasError() {
return
}

conn := r.Meta().ResourceExplorer2Client()
updateTimeout := timeouts.Update(ctx, new.Timeouts, r.defaultUpdateTimeout)

if !new.Type.Equal(old.Type) {
input := &resourceexplorer2.UpdateIndexTypeInput{
Expand Down Expand Up @@ -250,8 +260,13 @@ func (r *resourceIndex) Delete(ctx context.Context, request resource.DeleteReque
return
}

deleteTimeout, d := data.Timeouts.Delete(ctx, r.defaultDeleteTimeout)
response.Diagnostics.Append(d...)
if response.Diagnostics.HasError() {
return
}

conn := r.Meta().ResourceExplorer2Client()
deleteTimeout := timeouts.Delete(ctx, data.Timeouts, r.defaultDeleteTimeout)

tflog.Debug(ctx, "deleting Resource Explorer Index", map[string]interface{}{
"id": data.ID.ValueString(),
Expand Down Expand Up @@ -282,12 +297,12 @@ func (r *resourceIndex) ModifyPlan(ctx context.Context, request resource.ModifyP
}

type resourceIndexData struct {
ARN types.String `tfsdk:"arn"`
ID types.String `tfsdk:"id"`
Tags types.Map `tfsdk:"tags"`
TagsAll types.Map `tfsdk:"tags_all"`
Timeouts types.Object `tfsdk:"timeouts"`
Type types.String `tfsdk:"type"`
ARN types.String `tfsdk:"arn"`
ID types.String `tfsdk:"id"`
Tags types.Map `tfsdk:"tags"`
TagsAll types.Map `tfsdk:"tags_all"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
Type types.String `tfsdk:"type"`
}

func findIndex(ctx context.Context, conn *resourceexplorer2.Client) (*resourceexplorer2.GetIndexOutput, error) {
Expand Down

0 comments on commit 4eb52d3

Please sign in to comment.