Skip to main content
For Authlete 2.x documentation, see 2.x version.

First Steps

The Terraform provider does not support creating organizations, so the first step is to log in to the Authlete Management Console and create a new Organization, as shown below. If you don’t have an account, you can signup for a free trial account to get started. homepage

Creating the project

To get started let’s create a simple project with one Authlete service. You can find the source code on https://github.com/authlete/authlete-terraform-samples under simple_service directory. Keep in mind that Terraform projects have very loose structure requirements and are guided by conventions, so there is no hard requirement on the file structure. This sample shows a minimal configuration required for managing a service on Authlete using Terraform provider.

Setting your environment

In this sample, we will use environment variables to configure the Authlete Terraform plugin. The first thing you need is an Access Token, which authorizes the Terraform provider to securely call Authlete APIs. To create the Access Token, go to Organization Settings -> Basic Settings, then click Create under Access Tokens section. Once created, make sure to note the Token Value as it will be used in your environment configuration. Organization Token Next, click the Create Service button to open the New Service screen and select the appropriate Cluster. Once selected, copy the URL and extract the Organization and Server IDs from it. To access the Organization ID:
  1. Login to the Authlete Management Console
  2. Navigate to your Organization page.
  3. In the Organization Overview section, copy the Organization ID.
  4. Set it as an environment variable by running the following command in your terminal:
Replace {ORG_ID} with the actual ID you copied. New Service Setup To access the Server ID:
  1. Login to the Authlete Management Console
  2. Navigate the Service page.
  3. In the Service Overview section, copy the Cluster ID.
  4. Set it as an environment variable by running the following command in your terminal:
Replace the "{SERVER_ID}" with the Cluster ID you copied. New Service Setup Next, open your command line terminal and run the following commands to set your environment variables:
This will configure the necessary environment variables for the Terraform provider to interact with your Authlete instance. If you want these changes to persist across sessions, consider adding these export commands to your shell profile (e.g., ~/.bashrc, ~/.zshrc, or equivalent for your shell). This way, the environment variables will be automatically set every time you start a new terminal session.

Declaring the dependency to the provider and downloading it

The Authlete provider should be included in your project as a dependency and Terraform will take care of downloading it and making available to you. The providers dependencies are declared in a file provider.tf, by convention, and the structure is as below:
After this file is created, go to the command line and run the initialization command that will create your workspace:
At this stage Terraform has downloaded the Authlete provider and installed it locally for you. Please note the version number might have changed to make sure to use the correct version from terraform registry.

Declaring the service resource

In Terraform vocabulary, the Authlete Services and Clients are resources. So we need to declare a resource with the Authlete-specific type in order to have it created. Go ahead and create a main.tf as the content below:
In the first block, we are “configuring” an instance of the Authlete provider. This will instruct Terraform to actually instanciate some components that will talk to Authlete on your behalf. The second block is declaring a resource of type authlete_service with id as in the project. That name is specific to Terraform and it is not applied to the server-side configuration of Authlete. The properties in that block are straight forward: we are declaring an OAuth server that will accept only authorization code flow and the name on the server side will be MyDomainAS. The last 2 blocks are the instructions to Terraform to make available the id (which is the api_key) and the api_secret that you will use for configuring your AS and accessing that specific service in Authlete. To create that OAuth server backend on Authlete, go to command line and run the command below:
Congratulations! You have created a service in Authlete from Terraform. You can check the new service created in the Management Console by navigating to your Organization. New Service Setup If you want to check the API key and API secret of the created service you can use the commands below. If your components are also configured using Terraform, this wouldn’t be required.

Managing the configuration

With the service created, as there will be requirements changes, a change management process needs to be established. Keep in mind that Terraform has the concept of workspaces and that can be handy for managing Test, Preproduction and Production configurations of services on Authlete. Regardless of how are you managing the state changes and version control of the scripts, the approach for changing the Authlete Service is to change the resource in the .tf file and apply those changes. Let’s use the service created in the previous section and include support for the client credentials grant type. So we change the main.tf that we have created to be like below and apply those changes using the terraform apply command:
The Authlete provider has detected the inclusion of the CLIENT_CREDENTIALS grant type and Terraform is asking for your approval to change the service definition. After confirming the change the provider will fetch the status of that service from server and apply that specifically change.
Please note that if you have changed the service definition you need to bring your change to Terraform state using the command terraform import. Next Step