Public Preview: Terraform Visual Studio Code extension integrates Terraform Cloud

HashiCorp maintains a Terraform extension for Visual Studio Code in order to ensure that practitioners have a first-class editor experience. Our extension has the unique opportunity to accompany you on every step of your journey, from learning the syntax and writing your first lines of HashiCorp Configuration Language (HCL), to provisioning infrastructure as part of larger teams at companies serving millions of users. Today we announce a public preview of an expansion of the capabilities of our VS Code extension, adding a native integration with Terraform Cloud in order to better support professional individuals and teams who rely on Terraform Cloud for standardizing and managing their infrastructure automation and lifecycle.

How to opt-in

The new Terraform Cloud features are currently available in the pre-release version of our Terraform extension, which is the Visual Studio Code equivalent of a public beta channel. If you want to opt-in to receiving the new version in order to check out these capabilities before we roll them out to all users:

  1. Bring up the Extensions view in Visual Studio Code (Ctrl+Shift+X or ⇧⌘X)
  2. Search for the HashiCorp Terraform extension
  3. Click on “Switch to Pre-Release Version”

switch_to_preview

If the text on the button says “Switch to Release Version”, it means the pre-release version is already installed.

Getting started

The extension does not currently have a native login interface for Terraform Cloud and instead relies on you to supply a Terraform Cloud API token with user-level permissions. If you’re already using the Terraform CLI with Terraform Cloud, select the “Stored User Token” option in the login prompt to have VS Code use the same token you supplied to the CLI.

login_view

The other two options require you to manually supply a token. If you don’t already have one, you can easily generate one in the Terraform Cloud web interface on the User Tokens page:

You then need to supply this token to the extension as follows:

You can confirm it’s working properly by verifying that the new Terraform Cloud view allows you to pick an organization and then display all the workspaces under that organization that you have access to:

choose_org_view

workspace_view

Other features

The core capabilities of the new Terraform Cloud integration in our Visual Studio Code extension focus on providing a read-only view of workspaces and runs in order to reduce the amount of window- and context-switching you need to do. Instead of opening up the Terraform Cloud web interface in your browser to look up why a run failed and then switching back to VS Code to look for the configuration that caused the error, you can now view the apply log side-by-side with your code, allowing you to get back to debugging faster.

plan_apply_view

You can also hover over each run to see more information, such as which user initiated it, when, and what the outcome was, which is especially helpful when you’re collaborating on one workspace with a team:

workspace_run_view

To see the full list of features as we continue to add to them over the coming months, check out our documentation.

Give us feedback

The operating principle behind this initiative has been to move quickly and keep the featureset intentionally lean at the outset in order to provide a public preview for users faster, get feedback, and continue to iterate. The sky is the limit in terms of the Terraform Cloud features we theoretically could integrate into the VS Code extension, and your ideas and suggestions are crucial in helping us decide what to prioritize building next.

Since this is an open source project, please request new features, report bugs, or suggest improvements to our documentation in GitHub. For questions and general discussion, this HashiCorp Discuss forum is a great place to start. We’d especially like to hear whether you find the interface intuitive and how well it’s working for your use case, such as a setup with hundreds of workspaces or whether you’re using the VCS integration with Terraform Cloud.

How do you log out from Terraform Cloud or switch accounts? Every time I run the login again it just validates that my existing token works and doesn’t let me provide a different token.

In the Activity Bar there is the User Account icon next to the Settings gear icon, where all extensions that use VS Code Authentication can surface operations. Clicking that icon will bring up a menu listing authenticated users, selecting your user account for TFC will give you a menu to log out.

Unfortunately there is no direct VS Code API to call to log out a user, otherwise we would have had a matching command to do that for you.

Perfect, thank you! Is there a way that if you run a login it can override an existing token and start from scratch?

Right now if you want to use a different token, you will have to log out and log in.

I’m interested in the workflow you’re suggesting, do you mind opening a feature request in our repo with an example workflow that you would like enabled?