diff --git a/internal/provider/resource_application_user.go b/internal/provider/resource_application_user.go index 2e1aab6..4359cbc 100644 --- a/internal/provider/resource_application_user.go +++ b/internal/provider/resource_application_user.go @@ -175,23 +175,8 @@ func (r *ResourceApplicationUser) Read(ctx context.Context, req resource.ReadReq } var httpResp *client.GetUserRoleInAppResponse - err := retry.RetryContext(ctx, defaultApplicationUserReadTimeout, func() *retry.RetryError { - var err error - httpResp, err = r.client.GetUserRoleInAppWithResponse(ctx, r.orgId, data.AppID.ValueString(), data.UserID.ValueString()) - if err != nil { - return retry.NonRetryableError(err) - } - if httpResp.StatusCode() == 404 { - return retry.RetryableError(fmt.Errorf("waiting for application to be ready, status code: %d, body: %s", httpResp.StatusCode(), httpResp.Body)) - } - - if httpResp.StatusCode() != 200 { - return retry.NonRetryableError(fmt.Errorf("unable to read resource application user, unexpected status code: %d, body: %s", httpResp.StatusCode(), httpResp.Body)) - } - - return nil - }) + httpResp, err := r.client.GetUserRoleInAppWithResponse(ctx, r.orgId, data.AppID.ValueString(), data.UserID.ValueString()) if err != nil { resp.Diagnostics.AddError(HUM_CLIENT_ERR, fmt.Sprintf("Unable to read resource application user, got error: %s", err)) return @@ -203,6 +188,11 @@ func (r *ResourceApplicationUser) Read(ctx context.Context, req resource.ReadReq return } + if httpResp.StatusCode() != 200 { + resp.Diagnostics.AddError(HUM_API_ERR, fmt.Sprintf("Unable to get application user, unexpected status code: %d, body: %s", httpResp.StatusCode(), httpResp.Body)) + return + } + data.Role = types.StringValue(httpResp.JSON200.Role) // Save updated data into Terraform state diff --git a/internal/provider/resource_environment_type_user.go b/internal/provider/resource_environment_type_user.go index 19d6bf0..ae3d6bb 100644 --- a/internal/provider/resource_environment_type_user.go +++ b/internal/provider/resource_environment_type_user.go @@ -174,35 +174,23 @@ func (r *ResourceEnvironmentTypeUser) Read(ctx context.Context, req resource.Rea return } - var httpResp *client.GetUserRoleInEnvTypeResponse - err := retry.RetryContext(ctx, defaultEnvironmentTypeUserReadTimeout, func() *retry.RetryError { - var err error - httpResp, err = r.client.GetUserRoleInEnvTypeWithResponse(ctx, r.orgId, data.EnvTypeID.ValueString(), data.UserID.ValueString()) - if err != nil { - return retry.NonRetryableError(err) - } - - if httpResp.StatusCode() == 404 { - return retry.RetryableError(fmt.Errorf("waiting for application to be ready, status code: %d, body: %s", httpResp.StatusCode(), httpResp.Body)) - } - - if httpResp.StatusCode() != 200 { - return retry.NonRetryableError(fmt.Errorf("unable to read resource environment type user, unexpected status code: %d, body: %s", httpResp.StatusCode(), httpResp.Body)) - } - - return nil - }) + httpResp, err := r.client.GetUserRoleInEnvTypeWithResponse(ctx, r.orgId, data.EnvTypeID.ValueString(), data.UserID.ValueString()) if err != nil { resp.Diagnostics.AddError(HUM_CLIENT_ERR, fmt.Sprintf("Unable to read resource environment type user, got error: %s", err)) return } if httpResp.StatusCode() == 404 { - resp.Diagnostics.AddWarning("Application user not found", fmt.Sprintf("The application user (%s) was deleted outside Terraform", data.ID.ValueString())) + resp.Diagnostics.AddWarning("Environment Type user not found", fmt.Sprintf("The environment type user (%s) was deleted outside Terraform", data.ID.ValueString())) resp.State.RemoveResource(ctx) return } + if httpResp.StatusCode() != 200 { + resp.Diagnostics.AddError(HUM_API_ERR, fmt.Sprintf("Unable to get environment type user, unexpected status code: %d, body: %s", httpResp.StatusCode(), httpResp.Body)) + return + } + data.Role = types.StringValue(httpResp.JSON200.Role) // Save updated data into Terraform state diff --git a/internal/provider/resource_user.go b/internal/provider/resource_user.go index 732d811..2df5b95 100644 --- a/internal/provider/resource_user.go +++ b/internal/provider/resource_user.go @@ -167,6 +167,11 @@ func (r *ResourceUser) Read(ctx context.Context, req resource.ReadRequest, resp resp.Diagnostics.AddError(HUM_CLIENT_ERR, fmt.Sprintf("Unable to read user, got error: %s", err)) return } + if httpResp.StatusCode() == 404 { + resp.Diagnostics.AddWarning("User not found", fmt.Sprintf("The user (%s) was deleted outside Terraform", data.ID.ValueString())) + resp.State.RemoveResource(ctx) + return + } if httpResp.StatusCode() != 200 { resp.Diagnostics.AddError(HUM_API_ERR, fmt.Sprintf("Unable to read user, unexpected status code: %d, body: %s", httpResp.StatusCode(), httpResp.Body)) return