Skip to content

Commit 8a2ce7f

Browse files
authored
feat: implement basic provider for supabase project settings (#2)
* feat: initialise supabase api client * feat: define branch data source * feat: implement settings resource * fix: use jsontypes for parsing config * chore: reinitialise go mod dependencies * chore: remove duplicate ci runs * chore: update readme with provider example * chore: regenerate docs * fix: access set of project branches * chore: update docs * fix: remove sensitive value * fix: destroy orphan resource
1 parent 533b632 commit 8a2ce7f

27 files changed

+887
-562
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* @hashicorp/terraform-devex
1+
* @supabase/cli

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ on:
88
paths-ignore:
99
- 'README.md'
1010
push:
11+
branches:
12+
- main
1113
paths-ignore:
1214
- 'README.md'
1315

README.md

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
_This template repository is built on the [Terraform Plugin Framework](https://github.com/hashicorp/terraform-plugin-framework). The template repository built on the [Terraform Plugin SDK](https://github.com/hashicorp/terraform-plugin-sdk) can be found at [terraform-provider-scaffolding](https://github.com/hashicorp/terraform-provider-scaffolding). See [Which SDK Should I Use?](https://developer.hashicorp.com/terraform/plugin/framework-benefits) in the Terraform documentation for additional information._
44

5-
This repository is a *template* for a [Terraform](https://www.terraform.io) provider. It is intended as a starting point for creating Terraform providers, containing:
5+
This repository is a _template_ for a [Terraform](https://www.terraform.io) provider. It is intended as a starting point for creating Terraform providers, containing:
66

77
- A resource and a data source (`internal/provider/`),
88
- Examples (`examples/`) and generated documentation (`docs/`),
@@ -45,7 +45,56 @@ Then commit the changes to `go.mod` and `go.sum`.
4545

4646
## Using the provider
4747

48-
Fill this in for each provider
48+
- main.tf
49+
50+
```hcl
51+
terraform {
52+
required_providers {
53+
supabase = {
54+
source = "supabase/supabase"
55+
version = "~> 1.0"
56+
}
57+
}
58+
}
59+
60+
provider "supabase" {
61+
access_token = file("${path.module}/access-token")
62+
}
63+
64+
# Define a linked project variable as user input
65+
variable "linked_project" {
66+
type = string
67+
}
68+
69+
# Configure api settings for the linked project
70+
resource "supabase_settings" "production" {
71+
project_ref = var.linked_project
72+
73+
api = jsonencode({
74+
db_schema = "public,storage,graphql_public"
75+
db_extra_search_path = "public,extensions"
76+
max_rows = 1000
77+
})
78+
}
79+
80+
# Fetch all branches of a linked project
81+
data "supabase_branch" "all" {
82+
parent_project_ref = var.linked_project
83+
}
84+
85+
# Override settings for each preview branch
86+
resource "supabase_settings" "branch" {
87+
for_each = { for b in data.supabase_branch.all.branches : b.project_ref => b }
88+
89+
project_ref = each.key
90+
91+
api = jsonencode({
92+
db_schema = "public,storage,graphql_public"
93+
db_extra_search_path = "public,extensions"
94+
max_rows = 100
95+
})
96+
}
97+
```
4998

5099
## Developing the Provider
51100

@@ -57,7 +106,7 @@ To generate or update documentation, run `go generate`.
57106

58107
In order to run the full suite of Acceptance tests, run `make testacc`.
59108

60-
*Note:* Acceptance tests create real resources, and often cost money to run.
109+
_Note:_ Acceptance tests create real resources, and often cost money to run.
61110

62111
```shell
63112
make testacc

docs/data-sources/branch.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "supabase_branch Data Source - terraform-provider-supabase"
4+
subcategory: ""
5+
description: |-
6+
Branch data source
7+
---
8+
9+
# supabase_branch (Data Source)
10+
11+
Branch data source
12+
13+
## Example Usage
14+
15+
```terraform
16+
data "supabase_branch" "all" {
17+
parent_project_ref = "mayuaycdtijbctgqbycg"
18+
}
19+
```
20+
21+
<!-- schema generated by tfplugindocs -->
22+
## Schema
23+
24+
### Required
25+
26+
- `parent_project_ref` (String) Parent project ref
27+
28+
### Read-Only
29+
30+
- `branches` (Attributes Set) Branch databases (see [below for nested schema](#nestedatt--branches))
31+
32+
<a id="nestedatt--branches"></a>
33+
### Nested Schema for `branches`
34+
35+
Read-Only:
36+
37+
- `git_branch` (String) Git branch
38+
- `id` (String) Branch identifier
39+
- `project_ref` (String) Branch project ref

docs/data-sources/scaffolding_example.md

Lines changed: 0 additions & 30 deletions
This file was deleted.

docs/index.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
---
22
# generated by https://github.com/hashicorp/terraform-plugin-docs
3-
page_title: "scaffolding-framework Provider"
3+
page_title: "supabase Provider"
44
subcategory: ""
55
description: |-
66
77
---
88

9-
# scaffolding-framework Provider
9+
# supabase Provider
1010

1111

1212

1313
## Example Usage
1414

1515
```terraform
16-
provider "scaffolding" {
17-
# example configuration here
16+
provider "supabase" {
17+
access_token = ""
1818
}
1919
```
2020

@@ -23,4 +23,5 @@ provider "scaffolding" {
2323

2424
### Optional
2525

26-
- `endpoint` (String) Example provider attribute
26+
- `access_token` (String, Sensitive) Supabase access token
27+
- `endpoint` (String) Supabase API endpoint

docs/resources/scaffolding_example.md

Lines changed: 0 additions & 31 deletions
This file was deleted.

docs/resources/settings.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "supabase_settings Resource - terraform-provider-supabase"
4+
subcategory: ""
5+
description: |-
6+
Settings resource
7+
---
8+
9+
# supabase_settings (Resource)
10+
11+
Settings resource
12+
13+
## Example Usage
14+
15+
```terraform
16+
resource "supabase_settings" "production" {
17+
project_ref = "mayuaycdtijbctgqbycg"
18+
19+
api = jsonencode({
20+
db_schema = "public,storage,graphql_public"
21+
db_extra_search_path = "public,extensions"
22+
max_rows = 1000
23+
})
24+
}
25+
```
26+
27+
<!-- schema generated by tfplugindocs -->
28+
## Schema
29+
30+
### Required
31+
32+
- `project_ref` (String) Project reference ID
33+
34+
### Optional
35+
36+
- `api` (String) API settings as [serialised JSON](https://api.supabase.com/api/v1#/services/updatePostgRESTConfig)
37+
- `auth` (String) Auth settings as [serialised JSON](https://api.supabase.com/api/v1#/projects%20config/updateV1AuthConfig)
38+
- `pooler` (String) Pooler settings as serialised JSON
39+
- `storage` (String) Storage settings as serialised JSON
40+
41+
### Read-Only
42+
43+
- `id` (String) Project identifier

examples/data-sources/scaffolding_example/data-source.tf

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
data "supabase_branch" "all" {
2+
parent_project_ref = "mayuaycdtijbctgqbycg"
3+
}

0 commit comments

Comments
 (0)