Skip to content

Commit

Permalink
Merge pull request #188 from jfrog/GH-184-fix-environment-error-handling
Browse files Browse the repository at this point in the history
Ensure create/update funcs return early if errored for project_environment resource
  • Loading branch information
alexhung authored Dec 19, 2024
2 parents 6784387 + b288eb1 commit ed07533
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.9.3 (December 19, 2024). Tested on Artifactory 7.98.11 with Terraform 1.10.3 and OpenTofu 1.8.7

BUG FIXES:

* resource/project_environment: Fix error handling during creation/update where state shouldn't be stored/updated when there is API error. Issue: [#184](https://github.com/jfrog/terraform-provider-project/issues/184) PR: [#188](https://github.com/jfrog/terraform-provider-project/pull/188)

## 1.9.2 (November 26, 2024). Tested on Artifactory 7.98.9 with Terraform 1.9.8 and OpenTofu 1.8.6

IMPROVEMENTS:
Expand Down
9 changes: 4 additions & 5 deletions pkg/project/resource/resource_project_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package project
import (
"context"
"fmt"
"net/http"
"regexp"
"strings"

Expand Down Expand Up @@ -114,9 +113,11 @@ func (r *ProjectEnvironmentResource) Create(ctx context.Context, req resource.Cr
Post(ProjectEnvironmentUrl)
if err != nil {
utilfw.UnableToCreateResourceError(resp, err.Error())
return
}
if response.IsError() {
utilfw.UnableToCreateResourceError(resp, projectError.String())
return
}

plan.ID = types.StringValue(environment.Name)
Expand Down Expand Up @@ -148,10 +149,6 @@ func (r *ProjectEnvironmentResource) Read(ctx context.Context, req resource.Read
utilfw.UnableToRefreshResourceError(resp, err.Error())
return
}
if response.StatusCode() == http.StatusNotFound {
resp.State.RemoveResource(ctx)
return
}
if response.IsError() {
utilfw.UnableToRefreshResourceError(resp, projectError.String())
return
Expand Down Expand Up @@ -211,9 +208,11 @@ func (r *ProjectEnvironmentResource) Update(ctx context.Context, req resource.Up
Post(ProjectEnvironmentUrl + "/{environmentName}/rename")
if err != nil {
utilfw.UnableToUpdateResourceError(resp, err.Error())
return
}
if response.IsError() {
utilfw.UnableToUpdateResourceError(resp, projectError.String())
return
}

plan.ID = types.StringValue(environmentUpdate.NewName)
Expand Down

0 comments on commit ed07533

Please sign in to comment.