Skip to main content
This page is for Authlete 2.x. For current (3.0) documentation, see this page.

First Steps

The Terraform provider does not support creating the service owner account, so the first step is to retrieve the Service Owner API Key and Secret. You can try it on Authlete’s Shared Cloud by first creating a test account on the signup page, head to Your account page link and take note of API Key and API Secret. If you are using a dedicated setup, update the url to your Authlete SO console. Account Page

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.

Creating an Authlete account and setting your environment

In this sample, we will use environment variables to configure the Authlete Terraform plugin. To get started, head to your profile page and take note of API Key and API Secret. After taking note, go to command line and run the command line below:
If you are not using the Shared Cloud environment you need one additional environment variable like below:
You can also change your interpreter profile to make those changes permanent.

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 installed might the latest.

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 Service list on Service Owner console. 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