Skip to content

Commit 3d29602

Browse files
authored
Merge pull request #978 from hashicorp/TF-20458-improve-hcp-terraform-workspace-unlock-retry-messaging-in-terraform-cli
Adds ErrWorkspaceLockedStateVersionStillPending
2 parents ec9ee35 + fc4e1bf commit 3d29602

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# UNRELEASED
22

3+
## Enhancements
4+
5+
* `Workspaces`: The `Unlock` method now returns a `ErrWorkspaceLockedStateVersionStillPending` error if the latest state version upload is still pending within the platform. This is a retryable error. by @brandonc
6+
37
# v1.66.0
48

59
## Enhancements

errors.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ var (
6969
// ErrWorkspaceLockedByUser is returned when trying to unlock a workspace locked by a user.
7070
ErrWorkspaceLockedByUser = errors.New("unable to unlock workspace locked by user")
7171

72+
// ErrWorkspaceLockedStateVersionStillPending is returned when trying to unlock whose
73+
// latest state version is still pending.
74+
ErrWorkspaceLockedStateVersionStillPending = errors.New("unable to unlock workspace while state version upload is still pending")
75+
7276
// ErrWorkspaceStillProcessing is returned when a workspace is still processing state
7377
// to determine if it is safe to delete. "conflict" followed by newline is used to
7478
// preserve go-tfe version compatibility with the error constructed at runtime before it was

tfe.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -934,10 +934,10 @@ func parsePagination(body io.Reader) (*Pagination, error) {
934934
return &raw.Meta.Pagination, nil
935935
}
936936

937-
// checkResponseCode can be used to check the status code of an HTTP request.
938-
937+
// checkResponseCode refines typical API errors into more specific errors
938+
// if possible. It returns nil if the response code < 400
939939
func checkResponseCode(r *http.Response) error {
940-
if r.StatusCode >= 200 && r.StatusCode <= 299 {
940+
if r.StatusCode >= 200 && r.StatusCode <= 399 {
941941
return nil
942942
}
943943

workspace.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,9 @@ func (s *workspaces) Unlock(ctx context.Context, workspaceID string) (*Workspace
10541054
w := &Workspace{}
10551055
err = req.Do(ctx, w)
10561056
if err != nil {
1057+
if strings.Contains(err.Error(), "latest state version is still pending") {
1058+
return nil, ErrWorkspaceLockedStateVersionStillPending
1059+
}
10571060
return nil, err
10581061
}
10591062

0 commit comments

Comments
 (0)