Apply for invite to IaCP

Scalr Terraform Provider (Preview)

Overview

The Scalr Terraform provider can be used to manage the components within they Scalr IaCP. 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 token to your Terraform configuration file and the Scalr provider will use it automatically based on the hostname

OS

File name and location

Windows

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"
}

Scalr Provider Installation

Note

This a 3rd party provider which cannot be automatically downloaded by Terraform. This is expected to change on Terrafrom release 0.13.0.

The provider executables can be found here: https://github.com/Scalr/terraform-provider-scalr/releases

Using the Scalr Provider in a Remote Backend Workspace

If your template is running in a remote backed, e.g. Scalr IaCP the provider needs to be placed so it can be uploaded to the remote workspace at the time of a run.

  • For templates in VCS repos linked to IaCP workspaces the Scalr provider must be added to the VCS repo

  • For templates being run via the CLI the provider must be added to local directory/folder where the template is held

Follow these steps, note you MUST download the linux_amd64 binary regardless of your local operating system and version.

  1. Download the binary for linux_amd64, e,g, terraform-provider-scalr_0.0.0-rc2_linux_amd64.tar.gz

  2. In the VCS repo or your local directory create a directory tree as terraform.d/plugins/linux_amd64

  3. Unzip and copy the provider file terraform-provider-scalr to the directory created above

Now when you run terraform init; terraform apply, or a run is triggered by the VCS integration, the plugin will be automatically uploaded to the workspace.

Using the Scalr Provider in a Local Backend

If you are using the provider to manage resources in a Scalr IaCP system from a local workspace on you PC then the provider executable should be placed within the plugins folder of your workspace or the general plugins folder, for example:

Follow these steps:

  1. Download the correct binary for your OS, e,g, for Mac this will be terraform-provider-scalr_0.0.0-rc2_darwin_amd64.tar.gz

  2. Unzip and copy the provider file terraform-provider-scalr to either

{workspace}/terraform.d/plugins/darwin_amd64/terraform-provider-scalr

or

~/.terrafrom.d/plugins/terraform-provider-scalr

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"
  organization = "your_org_id"
  auto_apply = "true"
  terraform_version = "0.12.19"
   vcs_repo {
      identifier = "repo_org/repo_name"
      oauth_token_id = "the_vcs_id"
      }
  }

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