Skip to content

Commit

Permalink
Merge pull request #56 from Infisical/daniel/fix-project-membership-d…
Browse files Browse the repository at this point in the history
…rift

fix(project-user-resource): tf error if membership gets removed in infisical
  • Loading branch information
DanielHougaard authored Sep 24, 2024
2 parents 8a31eab + 3626183 commit ba3cf81
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
14 changes: 11 additions & 3 deletions internal/client/project_user.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package infisicalclient

import "fmt"
import (
"fmt"
"net/http"
)

func (client Client) InviteUsersToProject(request InviteUsersToProjectRequest) ([]ProjectMemberships, error) {
var inviteUsersToProjectResponse InviteUsersToProjectResponse
Expand Down Expand Up @@ -72,11 +75,16 @@ func (client Client) GetProjectUserByUsername(request GetProjectUserByUserNameRe
Post(fmt.Sprintf("api/v1/workspace/%s/memberships/details", request.ProjectID))

if err != nil {
return GetProjectUserByUserNameResponse{}, fmt.Errorf("CallCreateProject: Unable to complete api request [err=%s]", err)
return GetProjectUserByUserNameResponse{}, fmt.Errorf("CallGetProjectUserByUsername: Unable to complete api request [err=%s]", err)
}

if response.IsError() {
return GetProjectUserByUserNameResponse{}, fmt.Errorf("CallCreateProject: Unsuccessful response. [response=%s]", response)

if response.StatusCode() == http.StatusNotFound {
return GetProjectUserByUserNameResponse{}, ErrNotFound
}

return GetProjectUserByUserNameResponse{}, fmt.Errorf("CallGetProjectUserByUsername: Unsuccessful response. [response=%s]", response)
}

return projectUserResponse, nil
Expand Down
7 changes: 7 additions & 0 deletions internal/provider/resource/project_user_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,18 @@ func (r *ProjectUserResource) Read(ctx context.Context, req resource.ReadRequest
ProjectID: state.ProjectID.ValueString(),
Username: state.Username.ValueString(),
})

if err != nil {
if err == infisical.ErrNotFound {
resp.State.RemoveResource(ctx)
return
}

resp.Diagnostics.AddError(
"Error fetching user",
"Couldn't find user in project, unexpected error: "+err.Error(),
)

return
}

Expand Down

0 comments on commit ba3cf81

Please sign in to comment.