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.
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:
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.
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:
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:
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:
Once an action has started, the Terraform log output will stream directly back into the 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.
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.