Skip to content

feat: add project_id support to ory_json_web_key_set resource#132

Merged
KT-Doan merged 1 commit intomainfrom
feat/jwk-project-id
Mar 17, 2026
Merged

feat: add project_id support to ory_json_web_key_set resource#132
KT-Doan merged 1 commit intomainfrom
feat/jwk-project-id

Conversation

@KT-Doan
Copy link
Copy Markdown
Collaborator

@KT-Doan KT-Doan commented Mar 17, 2026

Description

Add project_id support to the ory_json_web_key_set resource. The resource previously required project_slug and project_api_key on the provider with no way to specify project_id at the resource level, making it unusable for project_id-based workflows.

The resource now accepts an optional project_id attribute that auto-resolves the project slug via the console API, eliminating the need to manually configure project_slug on the provider for JWK operations.

Changes

Client (internal/client/client.go):

  • ResolveProjectSlug(ctx, projectID) -- resolves project ID to slug via console API, with caching via sync.Map to avoid redundant API calls within a Terraform run
  • ProjectClientForProject(ctx, projectID) -- returns a project-scoped client for a given project ID

Resource (internal/resources/jwk/resource.go):

  • Added project_id attribute (optional, computed, requires replace)
  • CRUD operations resolve the project client from project_id
  • Validates that project_id is set (either on the resource or provider) before any operation
  • Import supports both project_id/set_id and plain set_id formats

Tests, docs, examples updated to demonstrate project_id usage.

Related Issues

Fixes #120

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist

  • I have read the CONTRIBUTING guide
  • My code follows the existing code style
  • I have added tests that prove my fix/feature works
  • I have updated documentation as needed
  • All new and existing tests pass (make test)
  • I have run the linter (make format)

Testing

  • Unit tests (make test-short -- all pass)
  • Acceptance tests (TestAccJWKResource_basic passes with create, read, and composite import)
  • Manual testing

Screenshots/Output

=== RUN   TestAccJWKResource_basic
    acctest.go:132: Using pre-created test project: 3fa274fe-... (slug: sad-moser-..., environment: prod)
--- PASS: TestAccJWKResource_basic (6.27s)

Security scans (make sec && make sec-trivy) -- 0 issues, no leaks."

Copilot AI review requested due to automatic review settings March 17, 2026 05:20
@KT-Doan KT-Doan self-assigned this Mar 17, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds project_id support to the ory_json_web_key_set Terraform resource by resolving a project slug via the console API and using a project-scoped client, enabling project-id-based workflows and composite import.

Changes:

  • Added console-backed project_id -> slug resolution with caching and a helper to build a project-scoped client.
  • Extended ory_json_web_key_set schema/CRUD/import to accept project_id and support project_id/set_id import.
  • Updated acceptance tests, docs, templates, and examples to demonstrate project_id usage.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
templates/resources/json_web_key_set.md.tmpl Documents immutability + composite import format including project_id.
internal/resources/jwk/testdata/basic.tf.tmpl Acceptance test config now sets project_id.
internal/resources/jwk/resource_test.go Acceptance test validates project_id and uses composite import ID.
internal/resources/jwk/resource.go Adds project_id attribute, resolves per-project client, updates import parsing.
internal/client/client.go Adds slug-resolution + caching and ProjectClientForProject.
examples/resources/ory_json_web_key_set/resource.tf Example updated to show provider-based and explicit project_id usage.
docs/resources/json_web_key_set.md Generated docs updated for project_id + composite import.

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

@KT-Doan KT-Doan force-pushed the feat/jwk-project-id branch from 7097630 to 28c0b6a Compare March 17, 2026 05:36
@KT-Doan KT-Doan requested a review from Copilot March 17, 2026 05:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds resource-level project_id support for ory_json_web_key_set by resolving project slug via the console API and using a project-scoped client, improving usability in project_id-based workflows.

Changes:

  • Add project_id attribute to the JWK Set resource schema, wiring CRUD to resolve a project-scoped client.
  • Add client helpers to resolve project_id -> slug via console API with in-run caching.
  • Update docs/examples/tests to demonstrate project_id usage and composite import (project_id/set_id).

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 Updates generated docs for immutability note and composite import format.
internal/resources/jwk/testdata/basic.tf.tmpl Updates acceptance test config template to set project_id.
internal/resources/jwk/resource_test.go Updates acceptance test to pass project_id and import using composite ID.
internal/resources/jwk/resource.go Adds project_id attribute, project client resolution helper, and composite import parsing.
internal/client/client.go Adds console-based slug resolution + cached project-scoped client creation.
examples/resources/ory_json_web_key_set/resource.tf Updates example usage to show provider-derived vs explicit project_id.
docs/resources/json_web_key_set.md Updates rendered docs for immutability note, examples, import, and project_id attribute.

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

@KT-Doan KT-Doan force-pushed the feat/jwk-project-id branch from 28c0b6a to 6fcbd1b Compare March 17, 2026 05:48
@KT-Doan KT-Doan requested a review from Copilot March 17, 2026 05:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds resource-level project_id support for ory_json_web_key_set, enabling project-id-based workflows by resolving a project-scoped client and supporting composite import IDs.

Changes:

  • Introduces project_id on the JWK resource (schema + CRUD + import parsing).
  • Adds client helpers to resolve project slug from project ID (with per-run caching) and to build project-scoped clients.
  • Updates docs/examples and acceptance test config to demonstrate/import using project_id.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
templates/resources/json_web_key_set.md.tmpl Updates generated docs template to include project_id immutability + composite import format.
internal/resources/jwk/testdata/basic.tf.tmpl Updates acceptance test template to set project_id.
internal/resources/jwk/resource_test.go Updates acceptance test to pass ORY_PROJECT_ID and import via composite ID.
internal/resources/jwk/resource.go Adds project_id attribute, routes CRUD through project-scoped client, and supports project_id/set_id import IDs.
internal/client/client.go Adds slug resolution (cached) and project-scoped client creation for a given project_id.
examples/resources/ory_json_web_key_set/resource.tf Updates example to show provider-based project context and explicit project_id.
docs/resources/json_web_key_set.md Updates docs with project_id and composite import format + attribute listing.

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

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
- Cache resolved slugs to avoid redundant API calls within a run
- Extract shared resolve logic into projectClient helper
- Validate import ID format when slash is present
- Preserve backward compatibility: fall back to provider's default
  client when no project_id is configured anywhere
- Support composite import format: project_id/set_id
- Update acceptance tests, examples, and documentation
@KT-Doan KT-Doan force-pushed the feat/jwk-project-id branch from 6fcbd1b to d92d57f Compare March 17, 2026 06:23
@KT-Doan KT-Doan merged commit e795544 into main Mar 17, 2026
10 checks passed
@KT-Doan KT-Doan deleted the feat/jwk-project-id branch March 17, 2026 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing project-id input for json_web_key_set terraform resource

3 participants