You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Same-apply: Create project and OAuth2 client together
145
+
# Use resource-level credentials when the project doesn't exist yet
146
+
resource "ory_oauth2_client" "same_apply" {
147
+
project_slug = ory_project.main.slug
148
+
project_api_key = ory_project_api_key.main.value
149
+
150
+
client_name = "Created with Project"
151
+
grant_types = ["client_credentials"]
152
+
token_endpoint_auth_method = "client_secret_post"
153
+
scope = "api:read api:write"
154
+
}
155
+
144
156
output "api_service_client_id" {
145
157
value = ory_oauth2_client.api_service.client_id
146
158
}
@@ -262,6 +274,33 @@ The provider supports both OIDC front-channel and back-channel logout:
262
274
-`frontchannel_logout_session_required` — Whether the client requires a session identifier (`sid`) in front-channel logout notifications.
263
275
-`backchannel_logout_session_required` — Whether the client requires a session identifier (`sid`) in back-channel logout notifications.
264
276
277
+
## Resource-Level Credentials (Same-Apply with Project Creation)
278
+
279
+
When creating an `ory_oauth2_client` in the same `terraform apply` as the `ory_project` it belongs to, the provider may not have project credentials at configuration time. Use the `project_slug` and `project_api_key` attributes to pass credentials directly to the resource:
280
+
281
+
```hcl
282
+
resource "ory_project" "main" {
283
+
name = "my-project"
284
+
environment = "prod"
285
+
}
286
+
287
+
resource "ory_project_api_key" "main" {
288
+
project_id = ory_project.main.id
289
+
name = "terraform-key"
290
+
}
291
+
292
+
resource "ory_oauth2_client" "api" {
293
+
project_slug = ory_project.main.slug
294
+
project_api_key = ory_project_api_key.main.value
295
+
296
+
client_name = "API Client"
297
+
grant_types = ["client_credentials"]
298
+
scope = "read write"
299
+
}
300
+
```
301
+
302
+
These attributes override the provider-level `project_slug` and `project_api_key`. If the provider already has valid project credentials, you do not need to set them on the resource.
303
+
265
304
## Import
266
305
267
306
OAuth2 clients can be imported using their client ID:
-`metadata` (String) Custom metadata as JSON string.
308
347
-`policy_uri` (String) URL of the client's privacy policy.
309
348
-`post_logout_redirect_uris` (List of String) List of allowed post-logout redirect URIs for OpenID Connect logout.
349
+
-`project_api_key` (String, Sensitive) Project API key for API access. Use this to pass credentials at the resource level when the provider is configured before the project exists (e.g., creating a project and OAuth2 client in the same apply). Overrides the provider-level project_api_key.
350
+
-`project_slug` (String) Project slug for API access. Use this to pass credentials at the resource level when the provider is configured before the project exists (e.g., creating a project and OAuth2 client in the same apply). Overrides the provider-level project_slug.
310
351
-`redirect_uris` (List of String) List of allowed redirect URIs for authorization code flow.
311
352
-`refresh_token_grant_access_token_lifespan` (String) Access token lifespan for refresh token grant (e.g., '1h', '30m').
312
353
-`refresh_token_grant_id_token_lifespan` (String) ID token lifespan for refresh token grant (e.g., '1h', '30m').
Description: "Project slug for API access. Use this to pass credentials at the resource level when the provider is configured before the project exists (e.g., creating a project and OAuth2 client in the same apply). Overrides the provider-level project_slug.",
168
+
Optional: true,
169
+
},
170
+
"project_api_key": schema.StringAttribute{
171
+
Description: "Project API key for API access. Use this to pass credentials at the resource level when the provider is configured before the project exists (e.g., creating a project and OAuth2 client in the same apply). Overrides the provider-level project_api_key.",
172
+
Optional: true,
173
+
Sensitive: true,
174
+
},
164
175
"client_name": schema.StringAttribute{
165
176
Description: "Human-readable name for the client.",
0 commit comments