This page is for Authlete 2.x. For current (3.0) documentation, see this page.
Managing OAuth clients with Terraform
Before we dig into the matter, a contextualization is required here as client management on the OAuth/OpenID Connect world has multiple angles and scenarios. The scenarios and use cases for the Authlete provider for Terraform is managing the clients that are structurally required on the Authorization Server. For example: clients that will be used by a web portal or API server, mobile apps of the company domain, or clients that are required to be transposed between environments.Support for Authlete Client
As with the support for services, Authlete provider allows creating, changing, and deleting OAuth clients on services, but as the clients exists within a service, that service needs to be configured either on the provider or in the client configuration, as we will see on this document. To represent an Authlete OAuth client, anauthlete_client Terraform resource is defined and the supported properties of the object can be found on the provider documentation page and is comprised all the properties available on the Authlete Developer Console.
Configuring the provider
If you don’t need to provision clients off two or more different services in one workspace, or simplistically one single execution of theapply command (which should be a rare case), the simplest approach for configuring the provider is to use the environment variables AUTHLETE_API_KEY and AUTHLETE_API_SECRET. That will set the service to be used when provisioning the client.
The examples here require that you have a service created on Authlete, it can be the service from simple_service example or the service created for you when your Authlete account was created.
In case you continue from simple_service, go ahead and take note of the output of the terraform output commands.
API Key and API Secret on the service detail page.

Declaring the clients and provisioning
As we have done for service, we start by declaring the dependency to the Authlete Provider and initializing the working env. You can check the section Declaring the dependency on Creating a project from scratch. The source of this example can be found onhttps://github.com/authlete/authlete-terraform-samples under
client_management directory.
After the initialization, create a main.tf file with the content as below:
portal identifier in Terraform and some
properties for a client like those that a Web Portal OIDC client would use.
The third and fourth blocks are declaring output variables that refer to OAuth client attributes. The sensitive attribute of
the client_secret instructs Terraform to never echo its value in the logs, but make it available when queried.
To create that client, run the command below in the same directory.
client_id_alias_enabled and some are
populated by the server, like user_info_sign_alg or token_auth_method. The attributes that are only server-side generated
are: id, client_id, and client_secret.
After the creation of the client, you can validate the creation on the Developer Console and/or query its client_id and
secret via output commands like below:
Changes on Client definition
Now any changes done on the client definition can be applied to Authlete by the provider. Challenged by requirements changes of refresh tokens for the portal client, for instance, you can go ahead and change the client definition to match the content like below:terraform apply command as below:

Configuring service on the client
If you need to manage clients of different Authlete services in the same workspace, you can specify the service’s API key and API secret on the client resource itself. This can be done using references to variables or other resources objects. As an example, we will use the same portal client from previous section and declare it for test and production services and the api key and secret will be references to variables. You can check the source of the example onhttps://github.com/authlete/authlete-terraform-samples under
client_services folder.
The input variables are defined, by convention, in a variables.tf file using a structure as below. Keep in mind that
this variable approach is used extensively on Terraform projects that are multi modules, so it can be a powerful mechanism
for defining very large deployments with multiple components.
service_api_key and service_api_secret
properties’ values are prefixed with a var. to scope the reference to input variables.
localhost:3000 for debugging purpose, while the production
client can redirect only to the production portal.
To run this example, you can define a variables file and provide it on command line when applying, as in the execution shown below: