Skip to content

Commit

Permalink
missed return statement
Browse files Browse the repository at this point in the history
  • Loading branch information
benPearce1 committed Nov 28, 2024
1 parent efd1d83 commit 9e504eb
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions octopusdeploy_framework/resource_deployment_freeze.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"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/diag"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/types"
"time"
Expand Down Expand Up @@ -63,11 +62,7 @@ func (f *deploymentFreezeResource) Read(ctx context.Context, req resource.ReadRe
return
}

diags := mapToState(ctx, state, deploymentFreeze, true)
if diags.HasError() {
resp.Diagnostics = diags
return
}
mapToState(state, deploymentFreeze, true)

resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}
Expand Down Expand Up @@ -96,11 +91,7 @@ func (f *deploymentFreezeResource) Create(ctx context.Context, req resource.Crea
return
}

diags = mapToState(ctx, plan, createdFreeze, false)
if diags.HasError() {
return
}

mapToState(plan, createdFreeze, false)
diags = resp.State.Set(ctx, plan)
resp.Diagnostics.Append(diags...)
}
Expand All @@ -124,6 +115,7 @@ func (f *deploymentFreezeResource) Update(ctx context.Context, req resource.Upda
updatedFreeze, err := mapFromState(plan)
if err != nil {
resp.Diagnostics.AddError("error while mapping deployment freeze", err.Error())
return
}

// this resource doesn't include scopes, need to copy it from the fetched resource
Expand All @@ -135,13 +127,11 @@ func (f *deploymentFreezeResource) Update(ctx context.Context, req resource.Upda
updatedFreeze, err = deploymentfreezes.Update(f.Config.Client, updatedFreeze)
if err != nil {
resp.Diagnostics.AddError("error while updating deployment freeze", err.Error())
}

diags := mapToState(ctx, plan, updatedFreeze, false)
if diags.HasError() {
return
}

mapToState(plan, updatedFreeze, false)

resp.Diagnostics.Append(resp.State.Set(ctx, plan)...)
}

Expand Down Expand Up @@ -170,15 +160,13 @@ func (f *deploymentFreezeResource) Delete(ctx context.Context, req resource.Dele
resp.State.RemoveResource(ctx)
}

func mapToState(ctx context.Context, state *deploymentFreezeModel, deploymentFreeze *deploymentfreezes.DeploymentFreeze, useSourceForDates bool) diag.Diagnostics {
func mapToState(state *deploymentFreezeModel, deploymentFreeze *deploymentfreezes.DeploymentFreeze, useSourceForDates bool) {
state.ID = types.StringValue(deploymentFreeze.ID)
state.Name = types.StringValue(deploymentFreeze.Name)
if useSourceForDates {
state.Start = types.StringValue(deploymentFreeze.Start.Format(time.RFC3339))
state.End = types.StringValue(deploymentFreeze.End.Format(time.RFC3339))
}

return nil
}

func mapFromState(state *deploymentFreezeModel) (*deploymentfreezes.DeploymentFreeze, error) {
Expand Down

0 comments on commit 9e504eb

Please sign in to comment.