Skip to content

Commit

Permalink
Add support for OpenTofu (#13)
Browse files Browse the repository at this point in the history
* Add support for OpenTufu

* Update node version

* Auto-build dist files

* Save

* Auto-build dist files

* Save

* Auto-build dist files

* Save

* Auto-build dist files

* Save

* Auto-build dist files

* Update README.md

* Update README.md

Add step to checkout your repo

---------

Co-authored-by: Github Action <[email protected]>
Co-authored-by: Ryan <[email protected]>
  • Loading branch information
3 people authored May 16, 2024
1 parent a1cdbae commit 33295fa
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 149 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@ on:
jobs:
build:
name: Build dist files and release
runs-on: 'ubuntu-latest'

runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: '16.15.1'
node-version: "20.11.1"

- name: Install dependencies
run: npm clean-install
Expand All @@ -47,4 +46,4 @@ jobs:
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create v${{ github.event.inputs.version }} --generate-notes
gh release create v${{ github.event.inputs.version }} --generate-notes
72 changes: 38 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,58 @@
# scalr-action

The `scalr-action` action is an action written in JavaScript that sets up the Scalr and Terraform CLI. The action does the following:
The `scalr-action` action is an action written in JavaScript that sets up the Scalr and OpenTofu/Terraform CLI. The action does the following:

- Downloads (and caching) the latest version of [Scalr CLI](https://github.com/Scalr/scalr-cli) and adds it to the `PATH`.
- Dowloads (and caching) a specific (or autodetected) version of Terraform CLI and adds it to the `PATH`.
- Dowloads (and caching) a specific (or autodetected) version of OpenTofu/Terraform CLI and adds it to the `PATH`.
- Configures the Scalr CLI and [Terraform CLI configuration file](https://www.terraform.io/docs/commands/cli-config.html) with a Scalr Hostname and Token.
- Optionally: Installs a script to wrap following calls of the `terraform` binary. Exposes the STDOUT, STDERR, and exit code as outputs named `stdout`, `stderr`, and `exitcode`. Enabled by default
- Optionally: Installs a script to wrap following calls of the `tofu/terraform` binary. Exposes the STDOUT, STDERR, and exit code as outputs named `stdout`, `stderr`, and `exitcode`. Enabled by default
- Optionally: [Terraform output variables](https://www.terraform.io/language/values/outputs) will be cached and converted to action variables. This is disabled by default.

After the action has been used, the following steps in the job can run the standard Terraform commands using [the GitHub Actions `run` command](https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepsrun).
After the action has been used, the following steps in the job can run the standard Opentofu/Terraform commands using [the GitHub Actions `run` command](https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepsrun).

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.

## Usage

Supported on the following GitHub Actions runners\:
* `ubuntu-latest`
* `windows-latest` (be sure to set the shell to Bash)
* `macos-latest`

If manually specifying a Terraform version, please remember to set the same version as set in your Scalr Workspace.
- `ubuntu-latest`
- `windows-latest` (be sure to set the shell to Bash)
- `macos-latest`

If manually specifying a Opentofu/Terraform version, please remember to set the same version as set in your Scalr Workspace.
You also need to generate a [Scalr API Token](https://docs.scalr.io/docs/creating-a-workspace-1#cli--workspace) and store it as a [GitHub Secret](https://docs.github.com/en/actions/security-guides/encrypted-secrets).

The following steps can access Terraform outputs:
The following steps can access OpenTofu/Terraform outputs:

```yaml
steps:
- uses: Scalr/scalr-action@v1
with:
scalr_hostname: '<your-account>.scalr.io'
scalr_token: ${{ secrets.SCALR_TOKEN }}
scalr_workspace: ws-abcdef123456
terraform_output: true
- uses: actions/checkout@v4
- uses: Scalr/scalr-action@v1
with:
scalr_hostname: "<your-account>.scalr.io"
scalr_token: ${{ secrets.SCALR_TOKEN }}
scalr_workspace: ws-abcdef123456
binary_output: true

- run: terraform init
- run: tofu init

- id: plan
run: terraform plan
- id: plan
run: tofu plan

- run: echo "${{ steps.plan.outputs.stdout }}"
- run: echo "${{ steps.plan.outputs.stderr }}"
- run: echo "${{ steps.plan.outputs.exitcode }}"
- 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
- id: apply
run: tofu apply -auto-approve

- run: echo ${{ steps.apply.outputs.server_ip }}
- run: echo ${{ steps.apply.outputs.server_ip }}
```
## Terraform configuration
## OpenTofu/Terraform configuration
Make sure your Terraform configuration includes the minimal parameters for Scalr.
Make sure your OpenTofu/Terraform configuration includes the minimal parameters for Scalr.
Here is an example for a minimal `main.tf`:

```
Expand All @@ -76,23 +78,25 @@ The action supports the following inputs:
- `scalr_workspace` - The Scalr workspace ID you plan on working in. This is required if you want to auto-detect Terraform version.
- `terraform_version` - The version of Terraform CLI. This must match the version set in your Scalr Workspace. It will be autodetected if left empty and workspace is set.
- `iac_platform` - Specifies if you want to use the `tofu` or `terraform` platform. Default is `terraform`.
- `binary_version` - The version of OpenTofu/Terraform CLI. This must match the version set in your Scalr Workspace. It will be autodetected if left empty and workspace is set.
- `terraform_wrapper` - Whether or not to install a wrapper to wrap calls of the `terraform` binary and expose its STDOUT, STDERR, and exit code
- `binary_wrapper` - Whether or not to install a wrapper to wrap calls of the `tofu/terraform` binary and expose its STDOUT, STDERR, and exit code
- `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.
- `binary_output` - true/false. Export OpenTofu/Terraform output variables as Action output variables. The OpenTofu/Terraform wrapper needs to be enabled for this to work. Example: `steps.<step-name>.outputs.<terraform_output_name>` This is disabled by default.
## Outputs
The following outputs are available for further steps that call the `terraform` binary if the wrapper has not been set to false.
The following outputs are available for further steps that call the `tofu/terraform` binary if the wrapper has not been set to false.
- `stdout` - The STDOUT of the call to the `terraform` binary.
- `stdout` - The STDOUT of the call to the `tofu/terraform` binary.
- `stderr` - The STDERR of the call to the `terraform` binary.
- `stderr` - The STDERR of the call to the `tofu/terraform` binary.
- `exitcode` - The exit code of the call to the `terraform` binary.
- `exitcode` - The exit code of the call to the `tofu/terraform` binary.
- `<terraform_output_var_name>` - Stores the Terraform output variables from last `terraform apply` run if terraform_output=true
- `<terraform_output_var_name>` - Stores the Terraform output variables from last `tofu/terraform apply` run if binary_output=true
## Scalr CLI
Expand Down
46 changes: 31 additions & 15 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,46 @@
name: 'Scalr Github Action'
description: 'Installs Scalr and Terraform CLI and configures them for Scalr use.'
author: 'Scalr'
name: "Scalr Github Action"
description: "Installs Scalr and Terraform CLI and configures them for Scalr use."
author: "Scalr"
inputs:
scalr_hostname:
description: 'The hostname of a Scalr install. Example: username.scalr.io.'
description: "The hostname of a Scalr install. Example: username.scalr.io."
required: true
scalr_token:
description: 'The API token to use.'
description: "The API token to use."
required: true
scalr_workspace:
description: 'The Scalr workspace ID you plan on working in. This is required if you want to autodetect Terraform version.'
description: "The Scalr workspace ID you plan on working in. This is required if you want to autodetect Terraform version."
required: false
iac_platform:
description: "Specifies if you want to use the tofu or terraform platform."
default: "terraform"
required: false
binary_version:
description: "The version of OpenTufu(Terraform CLI to install. Should match the version set in your Scalr Workspace. Will be autodetected if left empty and workspace is set."
required: false
binary_wrapper:
description: "Whether or not to install a wrapper to wrap subsequent calls of the `tofu/terraform` binary and expose its STDOUT, STDERR, and exit code as outputs named `stdout`, `stderr`, and `exitcode` respectively. Defaults to `true`."
default: "true"
required: false
binary_output:
description: "Export OpenTofu/Terraform output variables as Action output variables."
default: "false"
required: false
terraform_version:
description: '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.'
description: "Deprecated. Use `binary_version` instead."
required: false
terraform_wrapper:
description: 'Whether or not to install a wrapper to wrap subsequent calls of the `terraform` binary and expose its STDOUT, STDERR, and exit code as outputs named `stdout`, `stderr`, and `exitcode` respectively. Defaults to `true`.'
default: 'true'
description: "Deprecated. User `binary_wrapper` instead."
default: "true"
required: false
terraform_output:
description: 'Export Terraform output variables as Action output variables.'
default: false
description: "Deprecated. Use `binary_output` instead."
default: "false"
required: false

runs:
using: 'node16'
main: 'dist/terraform/index.js'
using: "node20"
main: "dist/terraform/index.js"
branding:
icon: 'terminal'
color: 'red'
icon: "terminal"
color: "red"
8 changes: 4 additions & 4 deletions dist/terraform/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/wrapper/index.js

Large diffs are not rendered by default.

Loading

0 comments on commit 33295fa

Please sign in to comment.