Skip to content

Commit a83fde6

Browse files
mikhail-putilovMikhail Putilov
authored andcommitted
Add example usage and expanded import documentation for Keycloak OpenID client in docs
Signed-off-by: Mikhail Putilov <[email protected]>
1 parent 6ff5be1 commit a83fde6

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

docs/resources/openid_client.md

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,27 @@ resource "keycloak_openid_client" "openid_client" {
107107
}
108108
```
109109

110+
## Example Usage with Existing default Client
111+
112+
```hcl
113+
resource "keycloak_realm" "realm" {
114+
realm = "my-realm"
115+
enabled = true
116+
}
117+
import {
118+
id = "${keycloak_realm.realm.id}/account"
119+
to = keycloak_openid_client.account
120+
}
121+
resource "keycloak_openid_client" "account" {
122+
realm_id = keycloak_realm.realm.id
123+
client_id = "account"
124+
enabled = false # disable account intentionally
125+
lifecycle {
126+
prevent_destroy = true
127+
}
128+
}
129+
```
130+
110131
## Argument Reference
111132

112133
- `realm_id` - (Required) The realm this client is attached to.
@@ -182,20 +203,36 @@ is set to `true`.
182203
}
183204
```
184205

185-
- `import` - (Optional) When `true`, the client with the specified `client_id` is assumed to already exist, and it will be imported into state instead of being created. This attribute is useful when dealing with clients that Keycloak creates automatically during realm creation, such as `account` and `admin-cli`. Note, that the client will not be removed during destruction if `import` is `true`.
186-
187206
## Attributes Reference
188207

189208
- `service_account_user_id` - (Computed) When service accounts are enabled for this client, this attribute is the unique ID for the Keycloak user that represents this service account.
190209
- `resource_server_id` - (Computed) When authorization is enabled for this client, this attribute is the unique ID for the client (the same value as the `.id` attribute).
191210

192211
## Import
193212

194-
Clients can be imported using the format `{{realm_id}}/{{client_keycloak_id}}`, where `client_keycloak_id` is the unique ID that Keycloak
195-
assigns to the client upon creation. This value can be found in the URI when editing this client in the GUI, and is typically a GUID.
213+
Clients can be imported using the two formats:
214+
215+
1. `{{realm_id}}/{{client_uuid}}`, where `client_uuid` is the UUID that KeyCloak assigns to the client upon creation.
216+
This value can be found in the URL when editing the client in an admin console.
217+
2. `{{realm_id}}/{{client_id}}`, where `client_id` is the human-readable client ID that KeyCloak requires when creating
218+
a client.
196219

197220
Example:
198221

199222
```bash
200223
terraform import keycloak_openid_client.openid_client my-realm/dcbc4c73-e478-4928-ae2e-d5e420223352
224+
terraform import keycloak_openid_client.account my-realm/account
225+
```
226+
227+
Or in HCL:
228+
```hcl
229+
import {
230+
id = "my-realm/dcbc4c73-e478-4928-ae2e-d5e420223352"
231+
to = keycloak_openid_client.openid_client
232+
}
233+
234+
import {
235+
id = "my-realm/account"
236+
to = keycloak_openid_client.account
237+
}
201238
```

0 commit comments

Comments
 (0)