feat: add console API fallback for identity schema data sources#105
feat: add console API fallback for identity schema data sources#105
Conversation
Add `project_id` attribute to `ory_identity_schema` and `ory_identity_schemas` data sources. When set (or when project_slug / project_api_key are not configured), schemas are read from the project config via the console API using only the workspace key. This unblocks bootstrap workflows where a new project is created and its schemas need to be referenced in the same Terraform run, without requiring project-level API credentials. Closes #104
There was a problem hiding this comment.
Pull request overview
Adds a project_id override to the ory_identity_schema and ory_identity_schemas data sources to enable listing/lookup of identity schemas via the console API (workspace key) as a fallback when project API credentials aren’t available—primarily to support project bootstrap workflows (Fixes #104).
Changes:
- Add optional
project_idattribute to both identity schema data sources and route schema retrieval through a console-API-based fallback when appropriate. - Introduce client helpers to detect project client configuration and to extract schemas from project config (console API /
GetProject) including base64 schema decoding. - Add unit + acceptance test coverage and update docs/templates/examples to document the new bootstrap workflow.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| templates/data-sources/identity_schemas.md.tmpl | Docs template: add tip about project_id and console API fallback |
| templates/data-sources/identity_schema.md.tmpl | Docs template: add tip about project_id and console API fallback |
| internal/datasources/identityschemas/datasource.go | Add project_id input and console API fallback for listing schemas |
| internal/datasources/identityschema/datasource.go | Add project_id input and console API fallback for reading a schema by ID |
| internal/datasources/identityschema/testdata/with_project_id.tf.tmpl | Acceptance test fixture for lookup via project_id |
| internal/datasources/identityschema/datasource_test.go | Add acceptance test covering console API path via project_id |
| internal/client/extract_schemas_test.go | Unit tests for schema extraction + HasProjectClient |
| internal/client/client.go | Add HasProjectClient, console-API schema listing helper, and config schema extraction |
| internal/acctest/acctest.go | Add helper to retrieve shared acceptance test project ID |
| examples/data-sources/ory_identity_schema/data-source.tf | Add bootstrap example using project_id |
| docs/data-sources/identity_schemas.md | Generated docs updated for project_id |
| docs/data-sources/identity_schema.md | Generated docs updated for project_id and bootstrap example |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Mark project_id as Optional+Computed to avoid "unexpected new value"
- Handle IsUnknown() on project_id with clear diagnostic
- Add nil guard on consoleClient in ListIdentitySchemasViaProject
- Return errors on malformed base64/JSON schemas instead of silently
dropping them
- Use empty object for preset schemas so json.Marshal produces "{}"
instead of "null"
- Add unit tests for invalid base64 and invalid JSON error paths
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…verage - Replace IsUnknown() error with fallback to provider's project_id, consistent with the organization data source pattern - Fail fast with clear diagnostic when console API path is selected but no project_id is available - Only write project_id to state when a non-empty value was resolved - Add acceptance test for ory_identity_schemas with project_id
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ~> **Tip:** Set `project_id` to list schemas via the console API (workspace key only). This is useful during project bootstrap when `project_slug` and `project_api_key` are not yet available. | ||
|
|
There was a problem hiding this comment.
This tip recommends using project_id (console API) but doesn’t mention an important behavioral difference: extractSchemasFromProjectConfig returns {} for non-base64:// schemas (e.g., presets like preset://username). That means the schema attribute may be an empty object when using this fallback. Consider documenting this limitation here so users don’t expect the full schema JSON for preset/URL-based entries.
| ~> **Tip:** Set `project_id` to look up schemas via the console API (workspace key only). This is useful during project bootstrap when `project_slug` and `project_api_key` are not yet available. | ||
|
|
There was a problem hiding this comment.
This tip recommends using project_id (console API) but doesn’t mention an important behavioral difference: extractSchemasFromProjectConfig returns {} for non-base64:// schemas (e.g., presets like preset://username). That means the schema attribute may be an empty object when using this fallback. Consider documenting this limitation here so users don’t expect the full schema JSON for preset/URL-based entries.
Description
Add
project_idattribute toory_identity_schemaandory_identity_schemasdata sources. When set (or whenproject_slug/project_api_keyare not configured), schemas are read from the project config via the console API using only the workspace key.This unblocks bootstrap workflows where a new project is created and its schemas need to be referenced in the same Terraform run, without requiring project-level API credentials.
Related Issues
Fixes #104
Type of Change
Checklist
make test)make format)Testing
extractSchemasFromProjectConfigandHasProjectClient(seeinternal/client/extract_schemas_test.go)TestAccIdentitySchemaDataSource_viaProjectID(seeinternal/datasources/identityschema/datasource_test.go)terraform planfails withproject API client not configured: project_slug and project_api_key are requiredterraform plansucceeds, data source reads schema via console API usingproject_idScreenshots/Output
Before (v26.0.2):
After (fix branch):