diff --git a/.changes/unreleased/ENHANCEMENTS-20240827-144337.yaml b/.changes/unreleased/ENHANCEMENTS-20240827-144337.yaml new file mode 100644 index 000000000..a4151ee6b --- /dev/null +++ b/.changes/unreleased/ENHANCEMENTS-20240827-144337.yaml @@ -0,0 +1,6 @@ +kind: ENHANCEMENTS +body: Document Terraform Stacks support +time: 2024-08-27T14:43:37.030208-04:00 +custom: + Issue: "1829" + Repository: vscode-terraform diff --git a/README.md b/README.md index 065d18c4c..b77bf617a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Terraform Extension for Visual Studio Code -The HashiCorp [Terraform Extension for Visual Studio Code (VS Code)](https://marketplace.visualstudio.com/items?itemName=HashiCorp.terraform) with the [Terraform Language Server](https://github.com/hashicorp/terraform-ls) adds editing features for [Terraform](https://www.terraform.io) files such as syntax highlighting, IntelliSense, code navigation, code formatting, module explorer and much more! +The HashiCorp [Terraform Extension for Visual Studio Code (VS Code)](https://marketplace.visualstudio.com/items?itemName=HashiCorp.terraform) with the [Terraform Language Server](https://github.com/hashicorp/terraform-ls) adds editing features for [Terraform](https://www.terraform.io) and Terraform Stacks files such as syntax highlighting, IntelliSense, code navigation, code formatting, module explorer and much more! ## Quick Start @@ -10,7 +10,7 @@ Get started writing Terraform configurations with VS Code in three steps: - **Step 2:** Install the [Terraform Extension for VS Code](https://marketplace.visualstudio.com/items?itemName=HashiCorp.terraform). -- **Step 3:** To activate the extension, open any folder or VS Code workspace containing Terraform files. Once activated, the Terraform language indicator will appear in the bottom right corner of the window. +- **Step 3:** To activate the extension, open any folder or VS Code workspace containing Terraform or Terraform Stacks files. Once activated, the Terraform language indicator will appear in the bottom right corner of the window. New to Terraform? Read the [Terraform Learning guides](https://learn.hashicorp.com/terraform) @@ -20,9 +20,11 @@ Read the [Troubleshooting Guide](#troubleshooting) for answers to common questio ## Features -- [IntelliSense](#intellisense-and-autocomplete) Edit your code with auto-completion of providers, resource names, data sources, attributes and more -- [Syntax validation](#syntax-validation) Provides inline diagnostics for invalid configuration as you type -- [Syntax highlighting](#syntax-highlighting) Highlighting syntax from Terraform 0.12 to 1.X +This extension provides both Terraform and Terraform Stacks language features. For most features Terraform Stacks support is implied, specific functionality is called out where approprite. + +- [IntelliSense](#intellisense-and-autocomplete) Edit your code with auto-completion of providers, resource names, data sources, attributes, components and more +- [Syntax validation](#syntax-validation) Provides inline diagnostics for invalid configurations as you type +- [Syntax highlighting](#syntax-highlighting) Highlighting syntax for Terraform 0.12 to 1.X and Terraform Stacks - [Code Navigation](#code-navigation) Navigate through your codebase with Go to Definition and Symbol support - [Code Formatting](#code-formatting) Format your code with `terraform fmt` automatically - [Code Snippets](#code-snippets) Shortcuts for common snippets like `for_each` and `variable` @@ -32,10 +34,16 @@ Read the [Troubleshooting Guide](#troubleshooting) for answers to common questio ### IntelliSense and Autocomplete +The Terraform Extension for VS Code provides IntelliSense support for Terraform and for Terraform Stacks. + IntelliSense is a general term for a variety of code editing features including: code completion, parameter info, quick info, and member lists. IntelliSense features are sometimes called by other names such as autocomplete, code completion, and code hinting. For Terraform constructs like resource and data, labels, blocks and attributes are auto completed both at the root of the document and inside other blocks. This also works for Terraform modules that are installed in the workspace, attributes and other constructs are autocompleted. +For Terraform Stacks constructs like component and resource, blocks and attributes are auto completed both at the root of the document and inside other blocks. This also works for Terraform Stack components that are installed in the workspace, attributes and other constructs are autocompleted. + +This means that you can benefit from auto-completion, parameter info, quick info, and member lists when working with both Terraform and Terraform Stacks files. Whether you're defining stacks, resources, or variables, the extension will provide context-specific completions to help you write your code more efficiently. + > **Note:** If there are syntax errors present in the document upon opening, intellisense may not provide all completions. Please fix the errors and reload the document and intellisense will return. See [hcl-lang#57](https://github.com/hashicorp/hcl-lang/issues/57) for more information. Invoking intellisense is performed through the [keyboard combination](https://code.visualstudio.com/docs/getstarted/keybindings) for your platform and the results depend on where the cursor is placed. @@ -56,13 +64,15 @@ Completing the snippet allows you to tab complete through each attribute and blo ### Syntax Validation -Terraform configuration files are validated when opened and on change, and invalid code is marked with diagnostics. +Terraform and Terraform Stacks configuration files are validated when opened and on change, and invalid code is marked with diagnostics. HCL syntax is checked for e.g. missing control characters like `}`, `"` or others in the wrong place. ![](docs/validation-rule-hcl.png) -Enhanced validation of selected Terraform language constructs in both `*.tf` and `*.tfvars` files based on detected Terraform version and provider versions is also provided. This can highlight deprecations, missing required attributes or blocks, references to undeclared variables and more, [as documented](https://github.com/hashicorp/terraform-ls/blob/main/docs/validation.md#enhanced-validation). +Enhanced validation of selected Terraform language constructs in both `*.tf` and `*.tfvars` files based on detected Terraform version and provider versions is also provided. This also works for Terraform Stacks language constructs in both `*.tfstack.hcl` and `*.tfdeploy.hcl` files. + +This can highlight deprecations, missing required attributes or blocks, references to undeclared variables and more, [as documented](https://github.com/hashicorp/terraform-ls/blob/main/docs/validation.md#enhanced-validation). ![](docs/validation-rule-missing-attribute.png) @@ -84,13 +94,15 @@ The extension also provides validation through [`terraform validate`](https://ww Terraform syntax highlighting recognizes language constructs from Terraform version 0.12 to 1.X. Terraform providers, modules, variables and other high-level constructs are recognized, as well as more complex code statements like `for` loops, conditional expressions, and other complex expressions. +Terraform Stacks syntax highlighting recognizes language constructs from Terraform version 1.9 to 1.X. + ![](docs/syntax.png) Some language constructs will highlight differently for older versions of Terraform that are incompatible with newer ways of expressing Terraform code. In these cases we lean toward ensuring the latest version of Terraform displays correctly and do our best with older versions. ### Code Navigation -While editing, you can right-click different identifiers to take advantage of several convenient commands +While editing, you can right-click different identifiers in Terraform and Terraform Stacks files to take advantage of several convenient commands: - `Go to Definition` (`F12`) navigates to the code that defines the construct where your cursor is. This command is helpful when you're working with Terraform modules and variables defined in other files than the currently opened document. - `Peek Definition` (`Alt+F12`) displays the relevant code snippet for the construct where your cursor is directly in the current editor instead of navigating to another file. @@ -101,6 +113,7 @@ While editing, you can right-click different identifiers to take advantage of se This extension utilizes [`terraform fmt`](https://www.terraform.io/cli/commands/fmt) to rewrite an open document to a canonical format and style. This command applies a subset of the [Terraform language style conventions](https://www.terraform.io/language/syntax/style), along with other minor adjustments for readability. +This works for both Terraform and Terraform Stacks files. See the [Formatting](#formatting) Configuration section for information on how to configure this feature.