Skip to content

Commit dbb542e

Browse files
feat: support configuring instance size for project resource (#75)
* chore: update cli to latest * chore: move ptr to utils * feat: support configuring instance size for project resource * docs: update json schema file --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 847dd15 commit dbb542e

File tree

9 files changed

+73
-56
lines changed

9 files changed

+73
-56
lines changed

docs/resources/project.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ resource "supabase_project" "test" {
1818
name = "foo"
1919
database_password = "bar"
2020
region = "us-east-1"
21+
instance_size = "micro"
22+
23+
lifecycle {
24+
ignore_changes = [
25+
database_password,
26+
instance_size,
27+
]
28+
}
2129
}
2230
```
2331

@@ -31,6 +39,10 @@ resource "supabase_project" "test" {
3139
- `organization_id` (String) Reference to the organization
3240
- `region` (String) Region where the project is located
3341

42+
### Optional
43+
44+
- `instance_size` (String) Desired instance size of the project
45+
3446
### Read-Only
3547

3648
- `id` (String) Project identifier

docs/schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@
134134
"description_kind": "markdown",
135135
"computed": true
136136
},
137+
"instance_size": {
138+
"type": "string",
139+
"description": "Desired instance size of the project",
140+
"description_kind": "markdown",
141+
"optional": true
142+
},
137143
"name": {
138144
"type": "string",
139145
"description": "Name of the project",

examples/resources/supabase_project/resource.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,12 @@ resource "supabase_project" "test" {
33
name = "foo"
44
database_password = "bar"
55
region = "us-east-1"
6+
instance_size = "micro"
7+
8+
lifecycle {
9+
ignore_changes = [
10+
database_password,
11+
instance_size,
12+
]
13+
}
614
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/hashicorp/terraform-plugin-go v0.22.2
1010
github.com/hashicorp/terraform-plugin-log v0.9.0
1111
github.com/hashicorp/terraform-plugin-testing v1.7.0
12-
github.com/supabase/cli v1.162.6
12+
github.com/supabase/cli v1.165.1
1313
gopkg.in/h2non/gock.v1 v1.1.2
1414
)
1515

@@ -82,7 +82,7 @@ require (
8282
golang.org/x/text v0.14.0 // indirect
8383
golang.org/x/tools v0.19.0 // indirect
8484
google.golang.org/appengine v1.6.8 // indirect
85-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
85+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
8686
google.golang.org/grpc v1.63.2 // indirect
8787
google.golang.org/protobuf v1.33.0 // indirect
8888
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
206206
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
207207
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
208208
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
209-
github.com/supabase/cli v1.162.6 h1:u3nVECHiLi4r9MsAkFNxtlWOtJngBnTbsSXTDRTcVS4=
210-
github.com/supabase/cli v1.162.6/go.mod h1:UzXI5ZUiaJVN5cL/eH3chthKRor2anir2qEv+fYwpk0=
209+
github.com/supabase/cli v1.165.1 h1:76tw6kLvG53PnSOKETR8y5UfP1JiKxfw3yHgHF+RYV0=
210+
github.com/supabase/cli v1.165.1/go.mod h1:8OuVTI9ZPEBdbH1XNw3egidhi+8hs5Rb2ys1QxR0Z1A=
211211
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
212212
github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI=
213213
github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
@@ -246,8 +246,8 @@ golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
246246
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
247247
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
248248
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
249-
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
250-
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
249+
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
250+
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
251251
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
252252
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
253253
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -284,8 +284,8 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
284284
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
285285
google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM=
286286
google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds=
287-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de h1:cZGRis4/ot9uVm639a+rHCUaG0JJHEsdyzSQTMX+suY=
288-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY=
287+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda h1:LI5DOvAxUPMv/50agcLLoo+AdWc1irS9Rzz4vPuD1V4=
288+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY=
289289
google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM=
290290
google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA=
291291
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=

internal/provider/project_resource.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type ProjectResourceModel struct {
3838
Name types.String `tfsdk:"name"`
3939
DatabasePassword types.String `tfsdk:"database_password"`
4040
Region types.String `tfsdk:"region"`
41+
InstanceSize types.String `tfsdk:"instance_size"`
4142
Id types.String `tfsdk:"id"`
4243
}
4344

@@ -67,6 +68,10 @@ func (r *ProjectResource) Schema(ctx context.Context, req resource.SchemaRequest
6768
MarkdownDescription: "Region where the project is located",
6869
Required: true,
6970
},
71+
"instance_size": schema.StringAttribute{
72+
MarkdownDescription: "Desired instance size of the project",
73+
Optional: true,
74+
},
7075
"id": schema.StringAttribute{
7176
MarkdownDescription: "Project identifier",
7277
Computed: true,
@@ -85,13 +90,11 @@ func (r *ProjectResource) Configure(ctx context.Context, req resource.ConfigureR
8590
}
8691

8792
client, ok := req.ProviderData.(*api.ClientWithResponses)
88-
8993
if !ok {
9094
resp.Diagnostics.AddError(
9195
"Unexpected Resource Configure Type",
9296
fmt.Sprintf("Expected *http.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
9397
)
94-
9598
return
9699
}
97100

@@ -103,13 +106,11 @@ func (r *ProjectResource) Create(ctx context.Context, req resource.CreateRequest
103106

104107
// Read Terraform plan data into the model
105108
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
106-
107109
if resp.Diagnostics.HasError() {
108110
return
109111
}
110112

111113
resp.Diagnostics.Append(createProject(ctx, &data, r.client)...)
112-
113114
if resp.Diagnostics.HasError() {
114115
return
115116
}
@@ -125,15 +126,13 @@ func (r *ProjectResource) Read(ctx context.Context, req resource.ReadRequest, re
125126

126127
// Read Terraform prior state data into the model
127128
resp.Diagnostics.Append(req.State.Get(ctx, &data)...)
128-
129129
if resp.Diagnostics.HasError() {
130130
return
131131
}
132132

133133
tflog.Trace(ctx, "read project")
134134

135135
resp.Diagnostics.Append(readProject(ctx, &data, r.client)...)
136-
137136
if resp.Diagnostics.HasError() {
138137
return
139138
}
@@ -147,7 +146,6 @@ func (r *ProjectResource) Update(ctx context.Context, req resource.UpdateRequest
147146

148147
// Read Terraform plan data into the model
149148
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
150-
151149
if resp.Diagnostics.HasError() {
152150
return
153151
}
@@ -162,13 +160,11 @@ func (r *ProjectResource) Delete(ctx context.Context, req resource.DeleteRequest
162160

163161
// Read Terraform prior state data into the model
164162
resp.Diagnostics.Append(req.State.Get(ctx, &data)...)
165-
166163
if resp.Diagnostics.HasError() {
167164
return
168165
}
169166

170167
resp.Diagnostics.Append(deleteProject(ctx, &data, r.client)...)
171-
172168
if resp.Diagnostics.HasError() {
173169
return
174170
}
@@ -184,13 +180,17 @@ func (r *ProjectResource) ImportState(ctx context.Context, req resource.ImportSt
184180
}
185181

186182
func createProject(ctx context.Context, data *ProjectResourceModel, client *api.ClientWithResponses) diag.Diagnostics {
187-
httpResp, err := client.CreateProjectWithResponse(ctx, api.CreateProjectJSONRequestBody{
183+
body := api.CreateProjectJSONRequestBody{
188184
OrganizationId: data.OrganizationId.ValueString(),
189185
Name: data.Name.ValueString(),
190186
DbPass: data.DatabasePassword.ValueString(),
191-
Region: api.CreateProjectBodyRegion(data.Region.ValueString()),
192-
})
187+
Region: api.V1CreateProjectBodyRegion(data.Region.ValueString()),
188+
}
189+
if !data.InstanceSize.IsNull() {
190+
body.DesiredInstanceSize = Ptr(api.DesiredInstanceSize(data.InstanceSize.ValueString()))
191+
}
193192

193+
httpResp, err := client.CreateProjectWithResponse(ctx, body)
194194
if err != nil {
195195
msg := fmt.Sprintf("Unable to create project, got error: %s", err)
196196
return diag.Diagnostics{diag.NewErrorDiagnostic("Client Error", msg)}
@@ -207,7 +207,6 @@ func createProject(ctx context.Context, data *ProjectResourceModel, client *api.
207207

208208
func readProject(ctx context.Context, data *ProjectResourceModel, client *api.ClientWithResponses) diag.Diagnostics {
209209
httpResp, err := client.GetProjectsWithResponse(ctx)
210-
211210
if err != nil {
212211
msg := fmt.Sprintf("Unable to read project, got error: %s", err)
213212
return diag.Diagnostics{diag.NewErrorDiagnostic("Client Error", msg)}
@@ -234,7 +233,6 @@ func readProject(ctx context.Context, data *ProjectResourceModel, client *api.Cl
234233

235234
func deleteProject(ctx context.Context, data *ProjectResourceModel, client *api.ClientWithResponses) diag.Diagnostics {
236235
httpResp, err := client.DeleteProjectWithResponse(ctx, data.Id.ValueString())
237-
238236
if err != nil {
239237
msg := fmt.Sprintf("Unable to delete project, got error: %s", err)
240238
return diag.Diagnostics{diag.NewErrorDiagnostic("Client Error", msg)}

internal/provider/project_resource_test.go

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,42 +20,34 @@ func TestAccProjectResource(t *testing.T) {
2020
gock.New("https://api.supabase.com").
2121
Post("/v1/projects").
2222
Reply(http.StatusCreated).
23-
JSON(api.ProjectResponse{
23+
JSON(api.V1ProjectResponse{
2424
Id: "mayuaycdtijbctgqbycg",
2525
Name: "foo",
2626
})
2727
gock.New("https://api.supabase.com").
2828
Get("/v1/projects").
2929
Reply(http.StatusOK).
30-
JSON(
31-
[]api.ProjectResponse{
32-
{
33-
Id: "mayuaycdtijbctgqbycg",
34-
Name: "foo",
35-
OrganizationId: "continued-brown-smelt",
36-
Region: "us-east-1",
37-
},
38-
},
39-
)
30+
JSON([]api.V1ProjectResponse{{
31+
Id: "mayuaycdtijbctgqbycg",
32+
Name: "foo",
33+
OrganizationId: "continued-brown-smelt",
34+
Region: "us-east-1",
35+
}})
4036
// Step 2: read
4137
gock.New("https://api.supabase.com").
4238
Get("/v1/projects").
4339
Reply(http.StatusOK).
44-
JSON(
45-
[]api.ProjectResponse{
46-
{
47-
Id: "mayuaycdtijbctgqbycg",
48-
Name: "foo",
49-
OrganizationId: "continued-brown-smelt",
50-
Region: "us-east-1",
51-
},
52-
},
53-
)
40+
JSON([]api.V1ProjectResponse{{
41+
Id: "mayuaycdtijbctgqbycg",
42+
Name: "foo",
43+
OrganizationId: "continued-brown-smelt",
44+
Region: "us-east-1",
45+
}})
5446
// Step 3: delete
5547
gock.New("https://api.supabase.com").
5648
Delete("/v1/projects/mayuaycdtijbctgqbycg").
5749
Reply(http.StatusOK).
58-
JSON(api.PostgrestConfigResponse{
50+
JSON(api.V1PostgrestConfigResponse{
5951
DbExtraSearchPath: "public,extensions",
6052
DbSchema: "public,storage,graphql_public",
6153
MaxRows: 1000,
@@ -77,7 +69,7 @@ func TestAccProjectResource(t *testing.T) {
7769
ResourceName: "supabase_project.test",
7870
ImportState: true,
7971
ImportStateVerify: true,
80-
ImportStateVerifyIgnore: []string{"database_password"},
72+
ImportStateVerifyIgnore: []string{"database_password", "instance_size"},
8173
},
8274
// Delete testing automatically occurs in TestCase
8375
},

internal/provider/settings_resource_test.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ import (
1313
"gopkg.in/h2non/gock.v1"
1414
)
1515

16-
func Ptr[T any](v T) *T {
17-
return &v
18-
}
19-
2016
func TestAccSettingsResource(t *testing.T) {
2117
// Setup mock api
2218
defer gock.OffAll()
@@ -36,15 +32,15 @@ func TestAccSettingsResource(t *testing.T) {
3632
gock.New("https://api.supabase.com").
3733
Get("/v1/projects/mayuaycdtijbctgqbycg/postgrest").
3834
Reply(http.StatusOK).
39-
JSON(api.PostgrestConfigResponse{
35+
JSON(api.V1PostgrestConfigResponse{
4036
DbExtraSearchPath: "public,extensions",
4137
DbSchema: "public,storage,graphql_public",
4238
MaxRows: 1000,
4339
})
4440
gock.New("https://api.supabase.com").
4541
Patch("/v1/projects/mayuaycdtijbctgqbycg/postgrest").
4642
Reply(http.StatusOK).
47-
JSON(api.PostgrestConfigResponse{
43+
JSON(api.V1PostgrestConfigResponse{
4844
DbExtraSearchPath: "public,extensions",
4945
DbSchema: "public,storage,graphql_public",
5046
MaxRows: 1000,
@@ -77,15 +73,15 @@ func TestAccSettingsResource(t *testing.T) {
7773
gock.New("https://api.supabase.com").
7874
Get("/v1/projects/mayuaycdtijbctgqbycg/postgrest").
7975
Reply(http.StatusOK).
80-
JSON(api.PostgrestConfigResponse{
76+
JSON(api.V1PostgrestConfigResponse{
8177
DbExtraSearchPath: "public,extensions",
8278
DbSchema: "public,storage,graphql_public",
8379
MaxRows: 1000,
8480
})
8581
gock.New("https://api.supabase.com").
8682
Get("/v1/projects/mayuaycdtijbctgqbycg/postgrest").
8783
Reply(http.StatusOK).
88-
JSON(api.PostgrestConfigResponse{
84+
JSON(api.V1PostgrestConfigResponse{
8985
DbExtraSearchPath: "public,extensions",
9086
DbSchema: "public,storage,graphql_public",
9187
MaxRows: 1000,
@@ -124,23 +120,23 @@ func TestAccSettingsResource(t *testing.T) {
124120
gock.New("https://api.supabase.com").
125121
Get("/v1/projects/mayuaycdtijbctgqbycg/postgrest").
126122
Reply(http.StatusOK).
127-
JSON(api.PostgrestConfigResponse{
123+
JSON(api.V1PostgrestConfigResponse{
128124
DbExtraSearchPath: "public,extensions",
129125
DbSchema: "public,storage,graphql_public",
130126
MaxRows: 1000,
131127
})
132128
gock.New("https://api.supabase.com").
133129
Patch("/v1/projects/mayuaycdtijbctgqbycg/postgrest").
134130
Reply(http.StatusOK).
135-
JSON(api.PostgrestConfigResponse{
131+
JSON(api.V1PostgrestConfigResponse{
136132
DbExtraSearchPath: "public,extensions",
137133
DbSchema: "public,storage,graphql_public",
138134
MaxRows: 100,
139135
})
140136
gock.New("https://api.supabase.com").
141137
Get("/v1/projects/mayuaycdtijbctgqbycg/postgrest").
142138
Reply(http.StatusOK).
143-
JSON(api.PostgrestConfigResponse{
139+
JSON(api.V1PostgrestConfigResponse{
144140
DbExtraSearchPath: "public,extensions",
145141
DbSchema: "public,storage,graphql_public",
146142
MaxRows: 100,

internal/provider/utils.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package provider
2+
3+
func Ptr[T any](v T) *T {
4+
return &v
5+
}

0 commit comments

Comments
 (0)