Scalr Terraform Provider

Overview

The Scalr Terraform provider can be used to manage the components within Scalr. This will allow you to automate the creation of workspaces, variables, VCS providers and much more.

Authentication

To start, an API token must be generated by clicking on your user on the top right of the screen and click on “TF API Access”:

../_images/api_access.png

This will provide you with an ID and token. The token will disappear after you click close. A user can have as many tokens as they want, it is up to that user to manage the tokens.

The token should then be used within the provider itself:

provider scalr {
  hostname = var.hostname
  token    = var.api_token
}

You can also add the token to your Terraform configuration file and the Scalr provider will use it automatically based on the hostname.

OS

File name and location

Windows

The file must be named named terraform.rc and placed in the relevant user’s %APPDATA% directory. The physical location of this directory depends on your Windows version and system configuration; use $env:APPDATA in PowerShell to find its location on your system.

All other

~/.terraformrc

provider scalr {
  hostname = var.hostname
}

Authentication with Shell Variables

The Scalr provider accepts the hostname and token values through shell variables SCALR_HOSTNAME and SCALR_TOKEN.

These variables can be set in your local shell, e.g.

export SCALR_HOSTNAME="my-account.scalr.io"
export SCALR_TOKEN="xxxxxxxxxxxxxxxxxx"

They can also be set in the variables tab of a Scalr workspace.

../_images/provider_vars.png

The provider block will not require any parameters if these are set.

provider scalr {}

Usage

Note

Terraform >= 13 or higher is required. Please see Terraform 0.12.x Scalr Provider Installation fort Terraform 0.12.x instructions.

To use the Scalr provider, simply add the following code block to your code:

terraform {
    required_providers {
        scalr = {
            source = "registry.scalr.io/scalr/scalr"
            version= "1.0.0-rc16"
        }
    }
}

Example usage and the verison list can be found here NEWWIN. The GPG key for the provider registry can be found here NEWWIN. The fingerprint is 1EF68C8041FC80714FF7A4017F685A20F41004C4.

If needed, the provider executables can be found here NEWWIN.

Example

Here is a basic example of creating a workspace with the provider:

provider scalr {
  hostname = var.hostname
  token    = var.api_token
}

resource scalr_workspace test {
  name         = "my-workspace-name"
  environment_id  = "env-xxxxxxxxx"
  auto_apply = "true"
  terraform_version = "0.12.19"
  vcs_provider_id = "my_vcs_provider"
  vcs_repo {
      identifier = "repo_org/repo_name"
      }
  }

Please see the full details for all of the resources in the list below.