Variables can be created as code through the Scalr Terraform Provider.

Terraform Variables

Scalr uses Terraform input variables the same exact way they are used in Terraform OSS, no extra configuration is needed other than having the option to create them directly in the Scalr UI. When Terraform variables are set directly in Scalr, Scalr will pass those variables to Terraform as a terraform.tfvars.json file. Please avoid using terraform.tfvars or terraform.tfvars.json as Scalr will overwrite these files during remote execution.

Terraform variables can be marked as sensitive or HCL values as needed:


Shell Variables

In addition to Terraform input variables, there are use cases for declaring shell variables in the run time environment. Shell variables can be declared in Scalr and are exported into the Terraform runtime environment using with export var=value.

Scalr uses this technique to automatically publish provider credentials to workspaces for the major cloud platforms (See Provider Credentials for more details). But, there are other use cases like using a common module across workspaces with only the variable files being different:

TF_CLI_ARGS_plan: -var-file=variables/prod.tfvars


Some other common use cases:

  • Provide credentials to providers that are not supported by Scalr Provider Credentials (see individual provider docs).

  • Pass in non-credentials configuration values to providers, such as location (see individual provider docs).

  • Set values for Terraform input variables with TF_VAR_{variable_name}={value}.

  • Pass in data to be used in scripts executed by provisioners or data "external" {}.

  • Set the log level with TF_LOG=TRACE

  • Set Terraform debug/behavioral variables NEWWIN.

Built-In Variables

The following shell variables are built into the runtime environment for use as needed:

  • SCALR_RUN_ID - The ID of the current run.

  • SCALR_HOSTNAME - The Scalr hostname.

  • SCALR_TERRAFORM_OPERATION - The current Terraform operation (plan or apply).

  • SCALR_TERRAFORM_EXIT_CODE - The exit code (0 or 1) of the previous operation (plan or apply) and only avilable in after hooks.

Setting Shell Variables

Scalr provides multi-scope shell variables that can be set at any scope and inherited at lower scopes. Variables set at higher scopes can, depending on the configuration of the variable, have their value overridden at lower scopes. The hierarchy is as follows.

  • Account

  • Environment -> Inherits from Account

  • Workspace -> Inherits from Account and Environment

Shell variables marked as “final” at any scope cannot be overridden by lower scopes. They can also be marked as “sensitive” to ensure the value is masked out in the Scalr UI, API and provider results and Terraform plan and state output.

Shell variables are set in the “Variables” section at each scope and are color coded to show the scope(s) they have been set at.

Example: Account scope

Account scope variables are created at the account scope and automatically shared with all environments and workspaces.


Use the slider icon to access the variable configuration detail. Make sure to “Save” after any changes to variables.

Example: Environment scope

Environment scope variables are created and assigned within the environments tab at the account scope. Once they are created an assigned to the environment, all workspaces in the enviornment will inherit the variable:


Note that some provider credential variables are shown. These have been inherited from cloud credentials set at account scope, hence the green icon.

Variables cab be overridden by creating a new variable of the same name at a lower scope. An overridden variable is shown as a group with the lowest scope, and therefore applicable value visible. The variable can be ungrouped using the button on the right so that variable can be edited or deleted.

Example: Workspace scope

Workspace scope variables are assigned within the variables tab at the workspace scope.