Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add status code to error message #11

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions docs/resources/project.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "supabase_project Resource - terraform-provider-supabase"
subcategory: ""
description: |-
Project resource
---

# supabase_project (Resource)

Project resource

## Example Usage

```terraform
resource "supabase_project" "test" {
organization_id = "continued-brown-smelt"
name = "foo"
database_password = "bar"
region = "us-east-1"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `database_password` (String, Sensitive) Password for the project database
- `name` (String) Name of the project
- `organization_id` (String) Reference to the organization
- `region` (String) Region where the project is located

### Read-Only

- `id` (String) Project identifier
6 changes: 4 additions & 2 deletions internal/provider/branch_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,13 @@ func (d *BranchDataSource) Read(ctx context.Context, req datasource.ReadRequest,
// provider client data and make a call using it.
httpResp, err := d.client.GetBranchesWithResponse(ctx, projectRef.ValueString())
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read branch, got error: %s", err))
msg := fmt.Sprintf("Unable to read branch, got error: %s", err)
resp.Diagnostics.AddError("Client Error", msg)
return
}
if httpResp.JSON200 == nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read branch, got error: %s", httpResp.Body))
msg := fmt.Sprintf("Unable to read branch, got status %d: %s", httpResp.StatusCode(), httpResp.Body)
resp.Diagnostics.AddError("Client Error", msg)
return
}

Expand Down
1 change: 1 addition & 0 deletions internal/provider/project_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func (r *ProjectResource) Update(ctx context.Context, req resource.UpdateRequest
return
}

// TODO: allow api to update project resource
msg := fmt.Sprintf("Update is not supported for project resource: %s", data.Id.ValueString())
resp.Diagnostics.Append(diag.NewErrorDiagnostic("Client Error", msg))
}
Expand Down
13 changes: 8 additions & 5 deletions internal/provider/settings_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,18 +219,21 @@ func readApiConfig(ctx context.Context, data *SettingsResourceModel, client *api
return diag.Diagnostics{diag.NewErrorDiagnostic("Client Error", msg)}
}
// Deleted project is an orphan resource, not returning error so it can be destroyed.
if httpResp.StatusCode() == http.StatusNotFound {
switch httpResp.StatusCode() {
case http.StatusNotFound, http.StatusNotAcceptable:
return nil
default:
break
}
if httpResp.JSON200 == nil {
msg := fmt.Sprintf("Unable to read api settings, got error: %s", httpResp.Body)
msg := fmt.Sprintf("Unable to read api settings, got status %d: %s", httpResp.StatusCode(), httpResp.Body)
return diag.Diagnostics{diag.NewErrorDiagnostic("Client Error", msg)}
}

httpResp.JSON200.JwtSecret = nil
value, err := json.Marshal(*httpResp.JSON200)
if err != nil {
msg := fmt.Sprintf("Unable to read api settings, got error: %s", err)
msg := fmt.Sprintf("Unable to read api settings, got marshal error: %s", err)
return diag.Diagnostics{diag.NewErrorDiagnostic("Client Error", msg)}
}

Expand All @@ -250,13 +253,13 @@ func updateApiConfig(ctx context.Context, data *SettingsResourceModel, client *a
return diag.Diagnostics{diag.NewErrorDiagnostic("Client Error", msg)}
}
if httpResp.JSON200 == nil {
msg := fmt.Sprintf("Unable to update api settings, got error: %s", httpResp.Body)
msg := fmt.Sprintf("Unable to update api settings, got status %d: %s", httpResp.StatusCode(), httpResp.Body)
return diag.Diagnostics{diag.NewErrorDiagnostic("Client Error", msg)}
}

value, err := json.Marshal(*httpResp.JSON200)
if err != nil {
msg := fmt.Sprintf("Unable to update api settings, got error: %s", err)
msg := fmt.Sprintf("Unable to update api settings, got marshal error: %s", err)
return diag.Diagnostics{diag.NewErrorDiagnostic("Client Error", msg)}
}

Expand Down
Loading