GitHub Action
Scalr Github Action
The scalr-action
action is a JavaScript action that sets up Scalr CLI and Terraform CLI in your GitHub Actions workflow by:
- Downloading (and caching) the latest version of Scalr CLI and adding it to the
PATH
. - Downloading (and caching) a specific (or autodetected) version of Terraform CLI and adding it to the
PATH
. - Configuring the Scalr CLI and Terraform CLI configuration file with a Scalr Hostname and API Token.
- Optionally: Installing a wrapper script to wrap subsequent calls of the
terraform
binary and expose its STDOUT, STDERR, and exit code as outputs namedstdout
,stderr
, andexitcode
respectively. This is enabled by default. - Optionally: Terraform output variables will be catched and converted to Action variables. This is disabled by default.
After you've used the action, subsequent steps in the same job can run arbitrary Terraform commands using the GitHub Actions run
syntax. This allows most Terraform commands to work exactly like they do on your local command line.
You will also have access to the Scalr CLI which communicates directly with the Scalr API and allows you to perform Scalr specific tasks, such as creating users, pull statistics etc.
This action can be run on ubuntu-latest
, windows-latest
, and macos-latest
GitHub Actions runners. When running on windows-latest
the shell should be set to Bash.
If manually specifying a Terraform version, please remember to set the same version as set in your Scalr Workspace. You also need to generate a Scalr API Token and store it as a GitHub Secret.
Subsequent steps can access Terraform outputs, if the optional wrapper is enabled.
steps:
- uses: Scalr/scalr-action@v1
with:
scalr_hostname: 'example.scalr.io'
scalr_token: ${{ secrets.SCALR_TOKEN }}
scalr_workspace: ws-u7f66t3oldrj4r2
terraform_output: true
- run: terraform init
- id: plan
run: terraform plan
- run: echo "${{ steps.plan.outputs.stdout }}"
- run: echo "${{ steps.plan.outputs.stderr }}"
- run: echo "${{ steps.plan.outputs.exitcode }}"
- id: apply
run: terraform apply -auto-approve
- run: echo ${{ steps.apply.outputs.server_ip }}
Make sure your Terraform configuration includes the minimal parameters for Scalr.
Here is an example for a minimal main.tf
:
terraform {
backend "remote" {
hostname = "example.scalr.io"
organization = "env-tq8cgtfobaj07u8"
workspaces {
name = "helloworld"
}
}
}
The action supports the following inputs:
-
scalr_hostname
- The hostname of a Scalr instance to place within the credentials block of the Terraform CLI configuration file. Example:example.scalr.io
. -
scalr_token
- The API token for a Scalr instance to place within the credentials block of the Terraform CLI configuration file. -
scalr_workspace
- The Scalr workspace ID you plan on working in. This is required if you want to autodetect Terraform version. -
terraform_version
- The version of Terraform CLI to install. Should match the version set in your Scalr Workspace. Will be autodetected if left empty and workspace is set. -
terraform_wrapper
- Whether or not to install a wrapper to wrap subsequent calls of theterraform
binary and expose its STDOUT, STDERR, and exit code as outputs namedstdout
,stderr
, andexitcode
respectively. This is enabled by default. -
terraform_output
- true/false. Export Terraform output variables as Action output variables. The Terraform wrapper needs to be enabled for this to work. Example:steps.<step-name>.outputs.<terraform_output_name>
This is disabled by default.
This action does not configure any outputs directly. However, the following outputs are available for subsequent steps that call the terraform
binary, given that terraform_wrapper has not been set to false.
-
stdout
- The STDOUT stream of the call to theterraform
binary. -
stderr
- The STDERR stream of the call to theterraform
binary. -
exitcode
- The exit code of the call to theterraform
binary. -
<terraform_output_var_name>
- Stores the Terraform output variables from lastterraform apply
run if terraform_output=true
More information about how to use the Scalr CLI provided by this Action, please refer to the Scalr CLI repository.