Skip to content

Commit

Permalink
Variables.GetByID return null variable when api error. (#784)
Browse files Browse the repository at this point in the history
* variables.GetByID return null variable when api error.

* handle none API error case
  • Loading branch information
HuyPhanNguyen authored Sep 17, 2024
1 parent 3e4649f commit be44617
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions octopusdeploy_framework/resource_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,20 @@ func (r *variableTypeResource) Read(ctx context.Context, req resource.ReadReques

variable, err := variables.GetByID(r.Config.Client, data.SpaceID.ValueString(), variableOwnerID.ValueString(), data.ID.ValueString())

// API don't return SpaceID with the variable, so we need to manually set it here from the state
variable.SpaceID = data.SpaceID.ValueString()
if err != nil {
if err := errors.ProcessApiErrorV2(ctx, resp, data, err, schemas.VariableResourceDescription); err != nil {
resp.Diagnostics.AddError("unable to load variable", err.Error())
apiError := errors.ProcessApiErrorV2(ctx, resp, data, err, schemas.VariableResourceDescription)
if apiError != nil {
resp.Diagnostics.AddError("unable to load variable", apiError.Error())
} else {
// If this is a non-API error
resp.Diagnostics.AddError(fmt.Sprintf("Error loading %s", schemas.VariableResourceDescription), err.Error())
}
return
}

// API don't return SpaceID with the variable, so we need to manually set it here from the state
variable.SpaceID = data.SpaceID.ValueString()

tflog.Info(ctx, fmt.Sprintf("Read variable: %+v", variable))
mapVariableToState(&data, variable)

Expand Down

0 comments on commit be44617

Please sign in to comment.