Skip to content

Commit

Permalink
chore: update read function to use new process api error func
Browse files Browse the repository at this point in the history
  • Loading branch information
hnrkndrssn committed Aug 9, 2024
1 parent 138f430 commit ffcddfa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
13 changes: 3 additions & 10 deletions octopusdeploy_framework/resource_runbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package octopusdeploy_framework
import (
"context"
"fmt"
"net/http"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/runbooks"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/internal/errors"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-log/tflog"
)

var _ resource.ResourceWithImportState = &runbookTypeResource{}
Expand Down Expand Up @@ -94,15 +93,9 @@ func (r *runbookTypeResource) Read(ctx context.Context, req resource.ReadRequest

runbook, err := runbooks.GetByID(r.Config.Client, state.SpaceID.ValueString(), state.ID.ValueString())
if err != nil {
if apiError, ok := err.(*core.APIError); ok {
if apiError.StatusCode == http.StatusNotFound {
tflog.Info(ctx, fmt.Sprintf("updating %s: %#v", schemas.RunbookResourceDescription, runbook))
resp.State.RemoveResource(ctx)
return
}
if err := errors.ProcessApiErrorV2(ctx, resp, state, err, schemas.RunbookResourceDescription); err != nil {
resp.Diagnostics.AddError("failed to load runbook", err.Error())
}

resp.Diagnostics.AddError("failed to load runbook", err.Error())
return
}

Expand Down
3 changes: 2 additions & 1 deletion octopusdeploy_framework/schemas/runbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ var defaultGuidedFailureModes = []string{
}

type RunbookTypeResourceModel struct {
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
ProjectID types.String `tfsdk:"project_id"`
Description types.String `tfsdk:"description"`
Expand All @@ -118,6 +117,8 @@ type RunbookTypeResourceModel struct {
DefaultGuidedFailureMode types.String `tfsdk:"default_guided_failure_mode"`
RunRetentionPolicy types.List `tfsdk:"retention_policy"`
ForcePackageDownload types.Bool `tfsdk:"force_package_download"`

ResourceModel
}

type RunbookRetentionPeriodModel struct {
Expand Down

0 comments on commit ffcddfa

Please sign in to comment.