CLI
OpenTofu
The commands below reference
terraform
, inserttofu
instead for openTofu.
Set Up
Note: This workspace type available is the Scalr remote backend is disabled.
Obtain a Scalr token from the UI in your profile settings or by running terraform login <account-name>.scalr.io
. When executing the login
command, Scalr will automatically create the credentials and store them in the credentials.tfrc.json
locally.
Set the following options:
- For a CLI-based workspace, you simply have to choose the working directory if one is needed.
- Add Scalr as the remote backend. The environment ID or name can be used as the organization. If the environment name has a space in it, the ID must be used:
terraform {
backend "remote" {
hostname = "<account-name>.scalr.io"
organization = "<scalr-environment-name>"
workspaces {
name = "<workspace-name>"
}
}
}
Terraform Init
Once the setup is complete, run terraform init
to connect to the workspace to the Scalr remote backend. From this point forward, the standard Terraform/Tofu commands will work as expected.
If there is an existing state file in the local system or state that was previously stored in another remote backend, then the terraform init
command will automatically migrate the state to Scalr. See Migrating to Scalr for more details.
Version Mismatch
If the workspace is pre-created manually in Scalr and the Terraform version of the workspace does not match the version of the CLI then the following error will be displayed:
Error reading local state: state snapshot was created by Terraform vx.x.x, which is newer than current vx.x.x;.
If you see this error, please ensure the Terraform version of the CLI matches the Terraform version of the workspace.
Provider Configurations
Before executing a run in a workspace, credentials must be added so that the code can authenticate to the Terraform provider during the run. This can be done through the Scalr provider configuration feature. Provider configurations give users a central place to manage their configurations and assign them for use within environments and workspaces.
Set Variables
Once the workspace is created and saved, variables might need to be added to the workspace if required. Find out more about setting shell and Terraform/Tofu variables here.
Terraform Plan & Apply
After the workspace has been created in Scalr and initialized with the the terraform init
command, a terraform plan
and/or a terraform apply
can be executed to make changes to the resources
Extra Settings
There are other optional settings that can be applied to all workspace types which can be found in workspace settings.
Updated about 1 month ago