Skip to content

Commit 9e3382b

Browse files
authored
Merge pull request #14 from appwrite/CLO-4192-move-to-go-sdk-v3
feat: move to go-sdk version `v3.0.0` with webhook field renames
2 parents 681a79b + 6c7b439 commit 9e3382b

29 files changed

Lines changed: 163 additions & 173 deletions

File tree

docs/resources/webhook.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ resource "appwrite_webhook" "order_created" {
1919
}
2020
2121
resource "appwrite_webhook" "user_events" {
22-
name = "user events"
23-
url = "https://api.example.com/webhooks/users"
24-
events = ["users.*.create", "users.*.update", "users.*.delete"]
25-
security = true
22+
name = "user events"
23+
url = "https://api.example.com/webhooks/users"
24+
events = ["users.*.create", "users.*.update", "users.*.delete"]
25+
tls = true
2626
}
2727
2828
resource "appwrite_webhook" "authenticated" {
29-
name = "authenticated webhook"
30-
url = "https://api.example.com/webhooks/secure"
31-
events = ["databases.*.collections.*.documents.*.create"]
32-
http_user = "webhook"
33-
http_pass = var.webhook_password
34-
security = true
29+
name = "authenticated webhook"
30+
url = "https://api.example.com/webhooks/secure"
31+
events = ["databases.*.collections.*.documents.*.create"]
32+
auth_username = "webhook"
33+
auth_password = var.webhook_password
34+
tls = true
3535
}
3636
```
3737

@@ -47,16 +47,16 @@ resource "appwrite_webhook" "authenticated" {
4747
### Optional
4848

4949
- `enabled` (Boolean) Whether the webhook is enabled. Defaults to true.
50-
- `http_pass` (String, Sensitive) HTTP basic authentication password.
51-
- `http_user` (String) HTTP basic authentication username.
50+
- `auth_password` (String, Sensitive) HTTP basic authentication password.
51+
- `auth_username` (String) HTTP basic authentication username.
5252
- `id` (String) The webhook ID.
5353
- `project_id` (String) The Appwrite project ID. Defaults to the provider-level project_id.
54-
- `security` (Boolean) Whether SSL/TLS certificate verification is enabled. Defaults to false.
54+
- `tls` (Boolean) Whether SSL/TLS certificate verification is enabled. Defaults to false.
5555

5656
### Read-Only
5757

5858
- `created_at` (String) The webhook creation timestamp in ISO 8601 format.
59-
- `signature_key` (String, Sensitive) Signature key for validating incoming webhooks.
59+
- `secret` (String, Sensitive) Secret key for validating incoming webhooks.
6060
- `updated_at` (String) The webhook last update timestamp in ISO 8601 format.
6161

6262
## Import

examples/resources/appwrite_webhook/resource.tf

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ resource "appwrite_webhook" "order_created" {
55
}
66

77
resource "appwrite_webhook" "user_events" {
8-
name = "user events"
9-
url = "https://api.example.com/webhooks/users"
10-
events = ["users.*.create", "users.*.update", "users.*.delete"]
11-
security = true
8+
name = "user events"
9+
url = "https://api.example.com/webhooks/users"
10+
events = ["users.*.create", "users.*.update", "users.*.delete"]
11+
tls = true
1212
}
1313

1414
resource "appwrite_webhook" "authenticated" {
15-
name = "authenticated webhook"
16-
url = "https://api.example.com/webhooks/secure"
17-
events = ["databases.*.collections.*.documents.*.create"]
18-
http_user = "webhook"
19-
http_pass = var.webhook_password
20-
security = true
15+
name = "authenticated webhook"
16+
url = "https://api.example.com/webhooks/secure"
17+
events = ["databases.*.collections.*.documents.*.create"]
18+
auth_username = "webhook"
19+
auth_password = var.webhook_password
20+
tls = true
2121
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/appwrite/terraform-provider-appwrite
33
go 1.25.0
44

55
require (
6-
github.com/appwrite/sdk-for-go/v2 v2.1.0
6+
github.com/appwrite/sdk-for-go/v3 v3.0.0
77
github.com/hashicorp/terraform-plugin-docs v0.24.0
88
github.com/hashicorp/terraform-plugin-framework v1.19.0
99
github.com/hashicorp/terraform-plugin-go v0.31.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki
1919
github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec=
2020
github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY=
2121
github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4=
22-
github.com/appwrite/sdk-for-go/v2 v2.1.0 h1:0AjrXSB7dY6oCLiGii1uO6OwdHZMpaZqG/qFk+4BCUY=
23-
github.com/appwrite/sdk-for-go/v2 v2.1.0/go.mod h1:xlGcA4IAIfsbReI526AnY8u6QjYHd87c4pRiJdCl7NE=
22+
github.com/appwrite/sdk-for-go/v3 v3.0.0 h1:kAdQeLkgN1ugyhYkgYQNl+r8G259FsOPcmmdhjqhHWU=
23+
github.com/appwrite/sdk-for-go/v3 v3.0.0/go.mod h1:lAU9JHfkpFJQwfwC+DcmzGlpB7sZ5Eeiqkh/0kHrSy0=
2424
github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI=
2525
github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
2626
github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY=

internal/common/helpers.go

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"strings"
88
"time"
99

10-
"github.com/appwrite/sdk-for-go/v2/appwrite"
11-
"github.com/appwrite/sdk-for-go/v2/client"
10+
"github.com/appwrite/sdk-for-go/v3/appwrite"
11+
"github.com/appwrite/sdk-for-go/v3/client"
1212
"github.com/hashicorp/terraform-plugin-framework/path"
1313
"github.com/hashicorp/terraform-plugin-framework/resource"
1414
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
@@ -79,34 +79,27 @@ func FormatError(err error) string {
7979
return err.Error()
8080
}
8181

82-
// DecodeColumn decodes the raw *interface{} response from GetColumn into a typed model.
83-
func DecodeColumn(raw *interface{}, target interface{}) error {
84-
if raw == nil {
85-
return fmt.Errorf("nil response from GetColumn")
86-
}
87-
switch v := (*raw).(type) {
88-
case string:
89-
return json.Unmarshal([]byte(v), target)
90-
default:
91-
b, err := json.Marshal(v)
92-
if err != nil {
93-
return fmt.Errorf("failed to marshal GetColumn response: %w", err)
94-
}
95-
return json.Unmarshal(b, target)
96-
}
97-
}
98-
99-
// GetColumnStatus extracts the status field from a raw GetColumn response.
100-
func GetColumnStatus(raw *interface{}) (string, error) {
101-
if raw == nil {
102-
return "", fmt.Errorf("nil response")
103-
}
104-
var generic map[string]interface{}
105-
if err := DecodeColumn(raw, &generic); err != nil {
106-
return "", err
107-
}
108-
status, _ := generic["status"].(string)
109-
return status, nil
82+
// GetColumnRaw fetches a column using a raw API call, bypassing the SDK's
83+
// type-matching logic which doesn't handle all column types (e.g. text,
84+
// longtext, mediumtext, varchar, point, line, polygon).
85+
func GetColumnRaw(c client.Client, databaseID, tableID, key string) (map[string]interface{}, error) {
86+
path := fmt.Sprintf("/tablesdb/%s/tables/%s/columns/%s", databaseID, tableID, key)
87+
resp, err := c.Call("GET", path, map[string]interface{}{}, map[string]interface{}{
88+
"databaseId": databaseID,
89+
"tableId": tableID,
90+
"key": key,
91+
})
92+
if err != nil {
93+
return nil, err
94+
}
95+
if !strings.HasPrefix(resp.Type, "application/json") {
96+
return nil, fmt.Errorf("unexpected response type: %s", resp.Type)
97+
}
98+
var result map[string]interface{}
99+
if err := json.Unmarshal([]byte(resp.Result.(string)), &result); err != nil {
100+
return nil, fmt.Errorf("failed to unmarshal column response: %w", err)
101+
}
102+
return result, nil
110103
}
111104

112105
// AttrCheck holds the result of an attribute mismatch check.
@@ -200,7 +193,7 @@ func WaitForDeploymentReady(ctx context.Context, getDeployment func() (string, e
200193

201194
// WaitForColumnAvailable polls a column until its status becomes "available",
202195
// with a maximum wait of 60 seconds.
203-
func WaitForColumnAvailable(ctx context.Context, getColumn func() (*interface{}, error), key string) error {
196+
func WaitForColumnAvailable(ctx context.Context, getColumn func() (interface{}, error), key string) error {
204197
deadline := time.After(60 * time.Second)
205198
for {
206199
select {
@@ -216,7 +209,10 @@ func WaitForColumnAvailable(ctx context.Context, getColumn func() (*interface{},
216209
return fmt.Errorf("error checking column %q status: %w", key, err)
217210
}
218211

219-
status, _ := GetColumnStatus(raw)
212+
var status string
213+
if m, ok := raw.(map[string]interface{}); ok {
214+
status, _ = m["status"].(string)
215+
}
220216
switch status {
221217
case "available":
222218
return nil

internal/provider/provider.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"context"
55
"os"
66

7-
"github.com/appwrite/sdk-for-go/v2/appwrite"
8-
"github.com/appwrite/sdk-for-go/v2/client"
7+
"github.com/appwrite/sdk-for-go/v3/appwrite"
8+
"github.com/appwrite/sdk-for-go/v3/client"
99
"github.com/hashicorp/terraform-plugin-framework/datasource"
1010
"github.com/hashicorp/terraform-plugin-framework/provider"
1111
"github.com/hashicorp/terraform-plugin-framework/provider/schema"

internal/services/backup/resource.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import (
44
"context"
55
"fmt"
66

7-
"github.com/appwrite/sdk-for-go/v2/appwrite"
8-
"github.com/appwrite/sdk-for-go/v2/backups"
9-
"github.com/appwrite/sdk-for-go/v2/id"
10-
"github.com/appwrite/sdk-for-go/v2/models"
7+
"github.com/appwrite/sdk-for-go/v3/appwrite"
8+
"github.com/appwrite/sdk-for-go/v3/backups"
9+
"github.com/appwrite/sdk-for-go/v3/id"
10+
"github.com/appwrite/sdk-for-go/v3/models"
1111
"github.com/appwrite/terraform-provider-appwrite/internal/common"
1212
"github.com/hashicorp/terraform-plugin-framework/diag"
1313
"github.com/hashicorp/terraform-plugin-framework/path"

internal/services/bucket/resource.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import (
44
"context"
55
"fmt"
66

7-
"github.com/appwrite/sdk-for-go/v2/appwrite"
8-
"github.com/appwrite/sdk-for-go/v2/id"
9-
"github.com/appwrite/sdk-for-go/v2/models"
10-
"github.com/appwrite/sdk-for-go/v2/storage"
7+
"github.com/appwrite/sdk-for-go/v3/appwrite"
8+
"github.com/appwrite/sdk-for-go/v3/id"
9+
"github.com/appwrite/sdk-for-go/v3/models"
10+
"github.com/appwrite/sdk-for-go/v3/storage"
1111
"github.com/appwrite/terraform-provider-appwrite/internal/common"
1212
"github.com/hashicorp/terraform-plugin-framework/diag"
1313
"github.com/hashicorp/terraform-plugin-framework/path"

internal/services/column/resource.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"encoding/json"
66
"fmt"
77

8-
"github.com/appwrite/sdk-for-go/v2/appwrite"
9-
"github.com/appwrite/sdk-for-go/v2/id"
10-
"github.com/appwrite/sdk-for-go/v2/tablesdb"
8+
"github.com/appwrite/sdk-for-go/v3/appwrite"
9+
"github.com/appwrite/sdk-for-go/v3/id"
10+
"github.com/appwrite/sdk-for-go/v3/tablesdb"
1111
"github.com/appwrite/terraform-provider-appwrite/internal/common"
1212
"github.com/hashicorp/terraform-plugin-framework/diag"
1313
"github.com/hashicorp/terraform-plugin-framework/resource"
@@ -468,8 +468,8 @@ func (r *columnResource) Create(ctx context.Context, req resource.CreateRequest,
468468
return
469469
}
470470

471-
if err := common.WaitForColumnAvailable(ctx, func() (*interface{}, error) {
472-
return tablesdbClient.GetColumn(databaseId, tableId, key)
471+
if err := common.WaitForColumnAvailable(ctx, func() (interface{}, error) {
472+
return common.GetColumnRaw(r.clients.ClientForProject(projectID), databaseId, tableId, key)
473473
}, key); err != nil {
474474
resp.Diagnostics.AddError("Error waiting for column to become available", err.Error())
475475
return
@@ -492,9 +492,9 @@ func (r *columnResource) Read(ctx context.Context, req resource.ReadRequest, res
492492
resp.Diagnostics.AddError("Missing project_id", err.Error())
493493
return
494494
}
495-
tablesdbClient := appwrite.NewTablesDB(r.clients.ClientForProject(projectID))
495+
sdkClient := r.clients.ClientForProject(projectID)
496496

497-
raw, err := tablesdbClient.GetColumn(state.DatabaseID.ValueString(), state.TableID.ValueString(), state.Key.ValueString())
497+
generic, err := common.GetColumnRaw(sdkClient, state.DatabaseID.ValueString(), state.TableID.ValueString(), state.Key.ValueString())
498498
if err != nil {
499499
if common.IsNotFoundError(err) {
500500
resp.State.RemoveResource(ctx)
@@ -504,12 +504,6 @@ func (r *columnResource) Read(ctx context.Context, req resource.ReadRequest, res
504504
return
505505
}
506506

507-
var generic map[string]interface{}
508-
if err := common.DecodeColumn(raw, &generic); err != nil {
509-
resp.Diagnostics.AddError("Error decoding column", err.Error())
510-
return
511-
}
512-
513507
responseJSON, _ := json.Marshal(generic)
514508
r.readResponseIntoState(ctx, responseJSON, &state, &resp.Diagnostics)
515509
state.ProjectID = types.StringValue(projectID)

internal/services/database/data_source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"fmt"
66

7-
"github.com/appwrite/sdk-for-go/v2/appwrite"
7+
"github.com/appwrite/sdk-for-go/v3/appwrite"
88
"github.com/appwrite/terraform-provider-appwrite/internal/common"
99
"github.com/hashicorp/terraform-plugin-framework/datasource"
1010
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"

0 commit comments

Comments
 (0)