Skip to content

Commit 4b022ec

Browse files
committed
✨ (docs/tutorial.md): add support for retrieving project API keys using data source
♻️ (docs/tutorial.md): refactor code to use Terraform data sources instead of hardcoded values
1 parent 2ded925 commit 4b022ec

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "supabase_project_apikeys Data Source - terraform-provider-supabase"
4+
subcategory: ""
5+
description: |-
6+
Project API Keys data source
7+
---
8+
9+
# supabase_project_apikeys (Data Source)
10+
11+
Project API Keys data source
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Required
19+
20+
- `project_id` (String) Project identifier
21+
22+
### Read-Only
23+
24+
- `anon_key` (String, Sensitive) Anonymous API key for the project
25+
- `service_role_key` (String, Sensitive) Service role API key for the project

docs/tutorial.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,27 @@ resource "supabase_project" "production" {
4141
ignore_changes = [database_password]
4242
}
4343
}
44+
45+
# Retrieve project API keys
46+
data "supabase_project_apikeys" "production" {
47+
project_id = supabase_project.production.id
48+
}
49+
50+
# Output the API keys (careful with sensitive data!)
51+
output "anon_key" {
52+
value = data.supabase_project_apikeys.production.anon_key
53+
sensitive = true
54+
}
55+
56+
output "service_role_key" {
57+
value = data.supabase_project_apikeys.production.service_role_key
58+
sensitive = true
59+
}
4460
```
4561

46-
Remember to substitute placeholder values with your own. For sensitive fields such as the password, consider storing and retrieving them from a secure credentials store.
62+
Remember to substitute placeholder values with your own. For sensitive fields such as the password, consider storing and retrieving them from a secure credentials store. The API keys are marked as sensitive and will be hidden in logs, but make sure to handle them securely in your workflow.
4763

48-
Next, run `terraform -chdir=module apply` to create the new project resource.
64+
Next, run `terraform -chdir=module apply` to create the new project resource and retrieve its API keys.
4965

5066
### Importing a project
5167

@@ -75,6 +91,11 @@ resource "supabase_project" "production" {
7591
ignore_changes = [database_password]
7692
}
7793
}
94+
95+
# Retrieve project API keys
96+
data "supabase_project_apikeys" "production" {
97+
project_id = supabase_project.production.id
98+
}
7899
```
79100

80101
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.

0 commit comments

Comments
 (0)