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 Cloud 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 Cloud 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.

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


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

Example: Environment scope


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

Variable VAR_THREE has been overridden at environment scope as shown by the green and blue icons. Variables are overridden by creating a new variable of the same name. 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