Terraform Visual Studio Code Extension
The HashiCorp Terraform Visual Studio Code (VS Code) extension adds syntax highlighting and other editing features for Terraform files using the Terraform Language Server.
- Manages installation and updates of the Terraform Language Server (terraform-ls), exposing its features:
- Initialized provider completion (resource names, data source names, attribute names)
- Includes syntax highlighting for
.tfvars files -- including all syntax changes new to Terraform 0.12
- Closes braces and quotes
variable syntax shortcuts (
IMPORTANT: After installing, you must perform a
terraform init to provide
terraform-ls with an up-to-date provider schemas. The language server will not work correctly without first completing this step!
- Install the extension from the Marketplace
- Reload VS Code after the installation (click the reload button next to the extension)
- Perform a
terraform init to provide
terraform-ls with an up-to-date provider schema
- Open your desired workspace and/or the root folder containing your Terraform files. Note: see Known Issues below about multi-folder workspaces
- Depending on your settings in VS Code, completion will start automatically (if not inside quotes/string literal, on certain trigger characters), or you can explicitly trigger completion via keyboard combination (Ctrl+Space on Windows, control+space on Mac).
This extension offers several configuration options. To modify these, navigate to the extension view within VS Code, select the settings cog and choose Extension settings, or alternatively, modify the
.vscode/settings.json file in the root of your working directory.
If you have multiple root modules in your workspace, you can configure the language server settings to identify them. Edit this through the VSCode Settings UI or add a
.vscode/settings.json file using the following template:
If you want to automatically search root modules in your workspace and exclude some folders, you can configure the language server settings to identify them.
To enable formatting, it is recommended that the following be added to the extension settings for the Terraform extension:
v2.0.0 is the first official release from HashiCorp, prior releases were by Mikael Olenfalk.
The 2.0.0 release integrates a new Language Server package from HashiCorp. The extension will install and upgrade terraform-ls to continue to add new functionality around code completion and formatting. See the terraform-ls CHANGELOG for details.
In addition, this new version brings the syntax highlighting up to date with all HCL2 features, as needed for Terraform 0.12 and above.
Configuration Changes Please note that in 2.x, the configuration differs from 1.4.0, if you are having issues with the Language Server starting, you can reset the configuration to the following:
See the CHANGELOG for more information.
If you are using a Terraform version prior to 0.12.0, you can install the pre-transfer version of this extension manually by following the instructions in the wiki.
- Multi-folder workspaces are not yet supported. (info)
- A number of different folder configurations (specifically when your root module is not a parent to any submodules) are not yet supported. (info)