Scalr
Scalr
September 10, 2024

Scalr VSCode Extension for Terraform & OpenTofu

By
Ryan Fee

Visual Studio Code (VSCode) is a free, open-source code editor developed by Microsoft that supports a wide range of programming languages, like Terraform and OpenTofu. One of the major benefits of VSCode is the vast number of tools that have a plugin to improve user experience. Most infrastructure as code developers are likely familiar with the Terraform plugin, but in this post, we are going to cover Scalr’s new VSCode extension that improves your Terraform and OpenTofu experience.

This new feature will allow users to update their Terraform code, see workspaces, and run results directly in VScode without having to open the Scalr UI.

The Scalr VSCode Extension

We recently released the beta version of the Scalr VSCode extension to reduce the amount of context switching that developers using Terraform and Scalr have to do. Some of the key features of this new feature include:

  • Listing all workspace and filtering by environment
  • Viewing all Terraform runs within a workspace and the run results
  • Running Terraform plan and apply from VSCode
  • Streaming of Terraform logs directly back into VSCode for active Terraform runs

Bringing information, such as all run results, into VSCode greatly reduces the amount of time users need to spend logging into the Scalr UI. One of our core principles at Scalr is to meet the users where they work and users can now make quick iterations to their Terraform code, test, and have the information they need right in the same editor.

If you still need to log into the UI for more information, each workspace has an icon next to it, which will log you directly into that workspace in Scalr.

Using the Extension

To use the extension, you must first download it from the VSCode marketplace.

Once the extension is installed, you can authenticate to Scalr by providing your account name and a token. IMPORTANT: Only the account name is needed. You do not need to add “.scalr.io” to the name. 

Once authenticated, the extension will automatically import all workspaces that you have access to with the ability to filter them by environment and workspace ID:

Workspaces download in VSCode

The icons to the left of the workspace name show the current status of the workspace, whether the last run was successful or not, or if a run has been executed at all.

After clicking on a workspace, you can also see all of the run history for the workspace as well as the run outputs:

Plan history in VSCode

Actions, such as `terraform plan`, `terraform apply`, `terraform refresh`, and `terraform destroy` can be taken directly from VSCode by clicking on “play” button next to the workspace name:

Actions available in VSCode

Once an action has started, the Terraform log output will stream directly back into the VSCode extension.

What’s Next for the Scalr VSCode Extension?

We want to continue to work with the community to build a VSCode extension that will improve the developer experience not only for Scalr, but also Terraform and OpenTofu. We encourage all users to report issues and raise feature requests directly in our GitHub repository.

Other Helpful Terraform VSCode Extensions

If you haven’t used it yet, the HashiCorp Terraform extension is very useful when developing new Terraform modules, configuration files, and general code formatting. The Terraform extension for VSCode will help with the speed of developing your configuration files by auto-completing providers, resource names, and data sources. On top of that, you will catch errors in your Terraform files faster by having the syntax validation built right into your editor. The syntax highlighting will auto-detect modules, providers, or even conditional expressions. The Terraform module explorer helps list the Terraform module used in the configuration that you are working on, allowing for easier code navigation. Lastly, if you’re doing local development, the extension gives you the ability to run `terraform init`, `terraform plan`, and `terraform apply` from the extension.

Other Scalr Features to Improve the Developer Experience

  • See how and why Scalr developed pull request comments in a way that gives the developers all of the information they need without making it too noisy.
  • Want to continue to use an existing workflow in GitHub actions but use Scalr as the backend? Check out our supported Github action here.
  • Use the Scalr CLI to interact with Scalr rather than fully learning the API.
Note: While this blog references Terraform, everything mentioned in here also applies to OpenTofu. New to OpenTofu? It is a fork of Terraform 1.5.7 as a result of the license change from MPL to BUSL by HashiCorp. OpenTofu is an open-source alternative to Terraform that is governed by the Linux Foundation. All features available in Terraform 1.5.7 or earlier are also available in OpenTofu. Find out the history of OpenTofu here.

Start using the OpenTofu & Terraform platform of the future.

A screenshot of the modules page in the Scalr Platform