feat: add project_id support to ory_json_web_key_set resource#131
Closed
feat: add project_id support to ory_json_web_key_set resource#131
Conversation
The JWK resource previously required project_slug and project_api_key on the provider, with no way to specify project_id at the resource level. This made it impossible to use with project_id-based workflows. Changes: - Add optional project_id attribute to ory_json_web_key_set (falls back to provider's project_id when not set) - Add ResolveProjectSlug and ProjectClientForProject methods to the client for resolving project_id to slug via the console API - Support composite import format: project_id/set_id - Update acceptance tests, examples, and documentation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds project_id support to the ory_json_web_key_set resource, enabling project-ID-based workflows by resolving the project slug via the Console API and improving import ergonomics.
Changes:
- Added
project_idas an optional/computed, replace-triggering attribute for the JWK resource and wired CRUD to use a project-scoped client. - Implemented Console API slug resolution and a helper to create a project-scoped client by
project_id. - Updated docs/examples/tests to demonstrate
project_idusage and composite import IDs.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| templates/resources/json_web_key_set.md.tmpl | Documentation template updated for project_id immutability and import formats. |
| internal/resources/jwk/testdata/basic.tf.tmpl | Acceptance test config updated to provide project_id. |
| internal/resources/jwk/resource_test.go | Acceptance test updated to assert project_id and use composite import ID. |
| internal/resources/jwk/resource.go | Added project_id attribute, client resolution, and composite import parsing. |
| internal/client/client.go | Added Console-based project slug resolver and project-scoped client helper. |
| examples/resources/ory_json_web_key_set/resource.tf | Examples updated to show provider vs explicit project_id. |
| docs/resources/json_web_key_set.md | Rendered docs updated for project_id and import formats. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+333
to
+335
| if !tfProjectID.IsNull() && !tfProjectID.IsUnknown() { | ||
| return tfProjectID.ValueString() | ||
| } |
Comment on lines
26
to
+37
| func TestAccJWKResource_basic(t *testing.T) { | ||
| projectID := os.Getenv("ORY_PROJECT_ID") | ||
|
|
||
| resource.Test(t, resource.TestCase{ | ||
| PreCheck: func() { acctest.AccPreCheck(t) }, | ||
| ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories(), | ||
| Steps: []resource.TestStep{ | ||
| // Create and Read | ||
| { | ||
| Config: acctest.LoadTestConfig(t, "testdata/basic.tf.tmpl", nil), | ||
| Config: acctest.LoadTestConfig(t, "testdata/basic.tf.tmpl", map[string]string{ | ||
| "ProjectID": projectID, | ||
| }), |
| ImportStateId: "tf-test-jwks", | ||
| ImportStateIdFunc: importStateJWKID, | ||
| ImportStateVerify: true, | ||
| }, |
Comment on lines
+107
to
+115
| "project_id": schema.StringAttribute{ | ||
| Description: "The project ID. If not set, uses the provider's project_id.", | ||
| Optional: true, | ||
| Computed: true, | ||
| PlanModifiers: []planmodifier.String{ | ||
| stringplanmodifier.UseStateForUnknown(), | ||
| stringplanmodifier.RequiresReplace(), | ||
| }, | ||
| }, |
Comment on lines
+339
to
347
| // resolveProjectClient returns a client configured for the given project. | ||
| // If project_id is provided, it resolves the slug via the console API. | ||
| // Otherwise, it falls back to the provider's project credentials. | ||
| func (r *JWKResource) resolveProjectClient(ctx context.Context, projectID string) (*client.OryClient, error) { | ||
| if projectID != "" { | ||
| return r.client.ProjectClientForProject(ctx, projectID) | ||
| } | ||
| return r.client, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add
project_idsupport to theory_json_web_key_setresource. The resource previously requiredproject_slugandproject_api_keyon the provider with no way to specifyproject_idat the resource level, making it unusable forproject_id-based workflows.The resource now accepts an optional
project_idattribute that auto-resolves the project slug via the console API, eliminating the need to manually configureproject_slugon the provider for JWK operations.Changes
Client (
internal/client/client.go):ResolveProjectSlug(ctx, projectID)-- resolves project ID to slug via console APIProjectClientForProject(ctx, projectID)-- returns a project-scoped client for a given project IDResource (
internal/resources/jwk/resource.go):project_idattribute (optional, computed, requires replace)project_idproject_id/set_idand plainset_idformatsTests, docs, examples updated to demonstrate
project_idusage.Related Issues
Fixes #120
Type of Change
Checklist
make test)make format)Testing
make test-short-- all pass)TestAccJWKResource_basicpasses with create, read, and composite import)Screenshots/Output
Security scans (
make sec && make sec-trivy) -- 0 issues, no leaks.