Skip to content

Commit

Permalink
Merge pull request #275 from mergenci/upbound-upjet-v5.70.0
Browse files Browse the repository at this point in the history
Implement deprecated diagnostic helper function locally
  • Loading branch information
mergenci authored Oct 7, 2024
2 parents 6ebbf11 + 61097fc commit 459ac5f
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions internal/service/mq/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/aws/aws-sdk-go/aws"

"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
Expand All @@ -29,6 +30,15 @@ import (
"github.com/hashicorp/terraform-provider-aws/names"
)

// diagErrorFramework is a helper method that creates an error diagnostic.
// This method was formerly at internal/create/errors.go
func diagErrorFramework(service, action, resource, id string, gotError error) diag.Diagnostic {
return diag.NewErrorDiagnostic(
create.ProblemStandardMessage(service, action, resource, id, nil),
gotError.Error(),
)
}

// @FrameworkResource(name="User")
func newResourceUser(_ context.Context) (resource.ResourceWithConfigure, error) {
return &resourceUser{}, nil
Expand Down Expand Up @@ -103,14 +113,14 @@ func (r *resourceUser) Create(ctx context.Context, request resource.CreateReques
}
_, err := conn.CreateUser(ctx, input)
if err != nil {
response.Diagnostics.Append(create.DiagErrorFramework(names.MQ, create.ErrActionCreating, ResourceNameUser, fmt.Sprintf("%s/%s", plan.BrokerID.ValueString(), plan.Username.ValueString()), err))
response.Diagnostics.Append(diagErrorFramework(names.MQ, create.ErrActionCreating, ResourceNameUser, fmt.Sprintf("%s/%s", plan.BrokerID.ValueString(), plan.Username.ValueString()), err))
return
}

// Create API call returns no data. Get resource details.
userDetails, err := findUserByID(ctx, conn, plan.BrokerID.ValueString(), plan.Username.ValueString())
if err != nil {
response.Diagnostics.Append(create.DiagErrorFramework(names.MQ, create.ErrActionCreating, ResourceNameUser, fmt.Sprintf("%s/%s", plan.BrokerID.ValueString(), plan.Username.ValueString()), err))
response.Diagnostics.Append(diagErrorFramework(names.MQ, create.ErrActionCreating, ResourceNameUser, fmt.Sprintf("%s/%s", plan.BrokerID.ValueString(), plan.Username.ValueString()), err))
return
}

Expand All @@ -136,7 +146,7 @@ func (r *resourceUser) Read(ctx context.Context, request resource.ReadRequest, r
return
}
if err != nil {
response.Diagnostics.Append(create.DiagErrorFramework(names.MQ, create.ErrActionReading, ResourceNameUser, fmt.Sprintf("%s/%s", state.BrokerID.ValueString(), state.ID.ValueString()), err))
response.Diagnostics.Append(diagErrorFramework(names.MQ, create.ErrActionReading, ResourceNameUser, fmt.Sprintf("%s/%s", state.BrokerID.ValueString(), state.ID.ValueString()), err))
return
}

Expand Down Expand Up @@ -170,7 +180,7 @@ func (r *resourceUser) Update(ctx context.Context, request resource.UpdateReques
}
_, err := conn.UpdateUser(ctx, input)
if err != nil {
response.Diagnostics.Append(create.DiagErrorFramework(names.MQ, create.ErrActionUpdating, ResourceNameUser, fmt.Sprintf("%s/%s", state.BrokerID.ValueString(), state.ID.ValueString()), err))
response.Diagnostics.Append(diagErrorFramework(names.MQ, create.ErrActionUpdating, ResourceNameUser, fmt.Sprintf("%s/%s", state.BrokerID.ValueString(), state.ID.ValueString()), err))
return
}
}
Expand All @@ -193,7 +203,7 @@ func (r *resourceUser) Delete(ctx context.Context, request resource.DeleteReques
}
_, err := conn.DeleteUser(ctx, input)
if err != nil {
response.Diagnostics.Append(create.DiagErrorFramework(names.MQ, create.ErrActionDeleting, ResourceNameUser, fmt.Sprintf("%s/%s", state.BrokerID.ValueString(), state.ID.ValueString()), err))
response.Diagnostics.Append(diagErrorFramework(names.MQ, create.ErrActionDeleting, ResourceNameUser, fmt.Sprintf("%s/%s", state.BrokerID.ValueString(), state.ID.ValueString()), err))
return
}
}
Expand Down

0 comments on commit 459ac5f

Please sign in to comment.