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 clicking on “TF API Access”:

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 |
All other |
|
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.
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 for 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-rc27"
}
}
}
Example usage and the version list can be found here . The GPG key for the provider registry can be found here
. The fingerprint is
1EF68C8041FC80714FF7A4017F685A20F41004C4
.
If needed, the provider executables can be found here .
Example¶
Here is a basic example of creating a workspace with the provider:
provider scalr {
hostname = var.hostname
token = var.api_token
}
data "scalr_vcs_provider" test {
name = "vcs-name"
account_id = "acc-xxxx" # if the user has access to more than one account
}
data "scalr_environment" test {
name = "env-name"
account_id = "acc-xxxx" # if the user has access to more than one account
}
resource "scalr_workspace" "vcs-driven" {
name = "my-workspace-name"
environment_id = data.scalr_environment.test.id
vcs_provider_id = data.scalr_vcs_provider.test.id
working_directory = "example/path"
vcs_repo {
identifier = "org/repo"
branch = "dev"
trigger_prefixes = ["stage", "prod"]
}
}
Please see the full details for all of the resources in the list below.
Data Sources¶
- scalr_access_policy Data Source
- scalr_agent_pool Data Source
- scalr_current_run Data Source
- scalr_endpoint Data Source
- scalr_environment Data Source
- scalr_iam_team Data Source
- scalr_iam_user Data Source
- scalr_module_version Data Source
- scalr_policy_group Data Source
- scalr_role Data Source
- scalr_vcs_provider Data Source
- scalr_webhook Data Source
- scalr_workspace Data Source
- scalr_workspace_ids Data Source
Resources¶
- scalr_access_policy Resource
- scalr_account_allowed_ips Resource
- scalr_agent_pool Resource
- scalr_agent_pool_token Resource
- scalr_endpoint Resource
- scalr_environment Resource
- scalr_iam_team Resource
- scalr_module Resource
- scalr_policy_group Resource
- scalr_policy_group_linkage Resource
- scalr_role Resource
- scalr_run_triggers Resource
- scalr_variable Resource
- scalr_vcs_provider Resource
- scalr_webhook resource
- scalr_workspace Resource