Skip to content

Commit f187d9a

Browse files
fix: rename project ref attribute for consistency (#216)
* fix: rename project ref attribute for consistency * docs: update json schema file * chore: simplify resource name * docs: update json schema file --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 4f4f315 commit f187d9a

File tree

8 files changed

+77
-77
lines changed

8 files changed

+77
-77
lines changed

docs/data-sources/project_apikeys.md renamed to docs/data-sources/apikeys.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
---
22
# generated by https://github.com/hashicorp/terraform-plugin-docs
3-
page_title: "supabase_project_apikeys Data Source - terraform-provider-supabase"
3+
page_title: "supabase_apikeys Data Source - terraform-provider-supabase"
44
subcategory: ""
55
description: |-
6-
Project API Keys data source
6+
API Keys data source
77
---
88

9-
# supabase_project_apikeys (Data Source)
9+
# supabase_apikeys (Data Source)
1010

11-
Project API Keys data source
11+
API Keys data source
1212

13+
## Example Usage
1314

15+
```terraform
16+
data "supabase_apikeys" "production" {
17+
project_ref = "mayuaycdtijbctgqbycg"
18+
}
19+
```
1420

1521
<!-- schema generated by tfplugindocs -->
1622
## Schema
1723

1824
### Required
1925

20-
- `project_id` (String) Project identifier
26+
- `project_ref` (String) Project reference ID
2127

2228
### Read-Only
2329

docs/schema.json

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,35 @@
222222
}
223223
},
224224
"data_source_schemas": {
225+
"supabase_apikeys": {
226+
"version": 0,
227+
"block": {
228+
"attributes": {
229+
"anon_key": {
230+
"type": "string",
231+
"description": "Anonymous API key for the project",
232+
"description_kind": "markdown",
233+
"computed": true,
234+
"sensitive": true
235+
},
236+
"project_ref": {
237+
"type": "string",
238+
"description": "Project reference ID",
239+
"description_kind": "markdown",
240+
"required": true
241+
},
242+
"service_role_key": {
243+
"type": "string",
244+
"description": "Service role API key for the project",
245+
"description_kind": "markdown",
246+
"computed": true,
247+
"sensitive": true
248+
}
249+
},
250+
"description": "API Keys data source",
251+
"description_kind": "markdown"
252+
}
253+
},
225254
"supabase_branch": {
226255
"version": 0,
227256
"block": {
@@ -288,35 +317,6 @@
288317
"description": "Pooler data source",
289318
"description_kind": "markdown"
290319
}
291-
},
292-
"supabase_project_apikeys": {
293-
"version": 0,
294-
"block": {
295-
"attributes": {
296-
"anon_key": {
297-
"type": "string",
298-
"description": "Anonymous API key for the project",
299-
"description_kind": "markdown",
300-
"computed": true,
301-
"sensitive": true
302-
},
303-
"project_id": {
304-
"type": "string",
305-
"description": "Project identifier",
306-
"description_kind": "markdown",
307-
"required": true
308-
},
309-
"service_role_key": {
310-
"type": "string",
311-
"description": "Service role API key for the project",
312-
"description_kind": "markdown",
313-
"computed": true,
314-
"sensitive": true
315-
}
316-
},
317-
"description": "Project API Keys data source",
318-
"description_kind": "markdown"
319-
}
320320
}
321321
}
322322
}

docs/tutorial.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,18 @@ resource "supabase_project" "production" {
4242
}
4343
}
4444
45-
# Retrieve project API keys
46-
data "supabase_project_apikeys" "production" {
47-
project_id = supabase_project.production.id
45+
# Retrieve project API keys (careful with sensitive data!)
46+
data "supabase_apikeys" "production" {
47+
project_ref = supabase_project.production.id
4848
}
4949
50-
# Output the API keys (careful with sensitive data!)
5150
output "anon_key" {
52-
value = data.supabase_project_apikeys.production.anon_key
51+
value = data.supabase_apikeys.production.anon_key
5352
sensitive = true
5453
}
5554
5655
output "service_role_key" {
57-
value = data.supabase_project_apikeys.production.service_role_key
56+
value = data.supabase_apikeys.production.service_role_key
5857
sensitive = true
5958
}
6059
```
@@ -80,7 +79,7 @@ import {
8079
id = var.linked_project
8180
}
8281
83-
# Create a project resource
82+
# Import a project resource
8483
resource "supabase_project" "production" {
8584
organization_id = "<your-org-id>"
8685
name = "tf-example"
@@ -91,11 +90,6 @@ resource "supabase_project" "production" {
9190
ignore_changes = [database_password]
9291
}
9392
}
94-
95-
# Retrieve project API keys
96-
data "supabase_project_apikeys" "production" {
97-
project_id = supabase_project.production.id
98-
}
9993
```
10094

10195
Run `terraform -chdir=module apply`. Enter the ID of your Supabase project at the prompt. If your local TF state is empty, your project will be imported from remote rather than recreated.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
data "supabase_apikeys" "production" {
2+
project_ref = "mayuaycdtijbctgqbycg"
3+
}

examples/examples.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ var (
1313
BranchDataSourceConfig string
1414
//go:embed data-sources/supabase_pooler/data-source.tf
1515
PoolerDataSourceConfig string
16+
//go:embed data-sources/supabase_apikeys/data-source.tf
17+
APIKeysDataSourceConfig string
1618
)

internal/provider/project_apikeys_data_source.go renamed to internal/provider/apikeys_data_source.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,35 @@ import (
1515
)
1616

1717
// Ensure provider defined types fully satisfy framework interfaces.
18-
var _ datasource.DataSource = &ProjectAPIKeysDataSource{}
18+
var _ datasource.DataSource = &APIKeysDataSource{}
1919

20-
func NewProjectAPIKeysDataSource() datasource.DataSource {
21-
return &ProjectAPIKeysDataSource{}
20+
func NewAPIKeysDataSource() datasource.DataSource {
21+
return &APIKeysDataSource{}
2222
}
2323

24-
// ProjectAPIKeysDataSource defines the data source implementation.
25-
type ProjectAPIKeysDataSource struct {
24+
// APIKeysDataSource defines the data source implementation.
25+
type APIKeysDataSource struct {
2626
client *api.ClientWithResponses
2727
}
2828

29-
// ProjectAPIKeysDataSourceModel describes the data source data model.
30-
type ProjectAPIKeysDataSourceModel struct {
31-
ProjectId types.String `tfsdk:"project_id"`
29+
// APIKeysDataSourceModel describes the data source data model.
30+
type APIKeysDataSourceModel struct {
31+
ProjectRef types.String `tfsdk:"project_ref"`
3232
AnonKey types.String `tfsdk:"anon_key"`
3333
ServiceRoleKey types.String `tfsdk:"service_role_key"`
3434
}
3535

36-
func (d *ProjectAPIKeysDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
37-
resp.TypeName = req.ProviderTypeName + "_project_apikeys"
36+
func (d *APIKeysDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
37+
resp.TypeName = req.ProviderTypeName + "_apikeys"
3838
}
3939

40-
func (d *ProjectAPIKeysDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
40+
func (d *APIKeysDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
4141
resp.Schema = schema.Schema{
42-
MarkdownDescription: "Project API Keys data source",
42+
MarkdownDescription: "API Keys data source",
4343

4444
Attributes: map[string]schema.Attribute{
45-
"project_id": schema.StringAttribute{
46-
MarkdownDescription: "Project identifier",
45+
"project_ref": schema.StringAttribute{
46+
MarkdownDescription: "Project reference ID",
4747
Required: true,
4848
},
4949
"anon_key": schema.StringAttribute{
@@ -60,7 +60,7 @@ func (d *ProjectAPIKeysDataSource) Schema(ctx context.Context, req datasource.Sc
6060
}
6161
}
6262

63-
func (d *ProjectAPIKeysDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
63+
func (d *APIKeysDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
6464
// Prevent panic if the provider has not been configured.
6565
if req.ProviderData == nil {
6666
return
@@ -78,23 +78,23 @@ func (d *ProjectAPIKeysDataSource) Configure(ctx context.Context, req datasource
7878
d.client = client
7979
}
8080

81-
func (d *ProjectAPIKeysDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
82-
var data ProjectAPIKeysDataSourceModel
81+
func (d *APIKeysDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
82+
var data APIKeysDataSourceModel
8383

8484
// Read Terraform configuration data into the model
8585
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
8686
if resp.Diagnostics.HasError() {
8787
return
8888
}
8989

90-
httpResp, err := d.client.V1GetProjectApiKeysWithResponse(ctx, data.ProjectId.ValueString(), &api.V1GetProjectApiKeysParams{})
90+
httpResp, err := d.client.V1GetProjectApiKeysWithResponse(ctx, data.ProjectRef.ValueString(), &api.V1GetProjectApiKeysParams{})
9191
if err != nil {
92-
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read project API keys, got error: %s", err))
92+
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read API keys, got error: %s", err))
9393
return
9494
}
9595

9696
if httpResp.JSON200 == nil {
97-
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read project API keys, got status %d: %s", httpResp.StatusCode(), httpResp.Body))
97+
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read API keys, got status %d: %s", httpResp.StatusCode(), httpResp.Body))
9898
return
9999
}
100100

@@ -107,7 +107,7 @@ func (d *ProjectAPIKeysDataSource) Read(ctx context.Context, req datasource.Read
107107
}
108108
}
109109

110-
tflog.Trace(ctx, "read project API keys")
110+
tflog.Trace(ctx, "read API keys")
111111

112112
// Save data into Terraform state
113113
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)

internal/provider/project_apikeys_data_source_test.go renamed to internal/provider/apikeys_data_source_test.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1111
"github.com/supabase/cli/pkg/api"
12+
"github.com/supabase/terraform-provider-supabase/examples"
1213
"gopkg.in/h2non/gock.v1"
1314
)
1415

@@ -36,18 +37,12 @@ func TestAccProjectAPIKeysDataSource(t *testing.T) {
3637
Steps: []resource.TestStep{
3738
// Read testing
3839
{
39-
Config: testAccProjectAPIKeysDataSourceConfig,
40+
Config: examples.APIKeysDataSourceConfig,
4041
Check: resource.ComposeAggregateTestCheckFunc(
41-
resource.TestCheckResourceAttr("data.supabase_project_apikeys.production", "anon_key", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.anon"),
42-
resource.TestCheckResourceAttr("data.supabase_project_apikeys.production", "service_role_key", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.service_role"),
42+
resource.TestCheckResourceAttr("data.supabase_apikeys.production", "anon_key", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.anon"),
43+
resource.TestCheckResourceAttr("data.supabase_apikeys.production", "service_role_key", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.service_role"),
4344
),
4445
},
4546
},
4647
})
4748
}
48-
49-
const testAccProjectAPIKeysDataSourceConfig = `
50-
data "supabase_project_apikeys" "production" {
51-
project_id = "mayuaycdtijbctgqbycg"
52-
}
53-
`

internal/provider/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (p *SupabaseProvider) DataSources(ctx context.Context) []func() datasource.
9696
return []func() datasource.DataSource{
9797
NewBranchDataSource,
9898
NewPoolerDataSource,
99-
NewProjectAPIKeysDataSource,
99+
NewAPIKeysDataSource,
100100
}
101101
}
102102

0 commit comments

Comments
 (0)