# Terraform

[Terraform](https://developer.hashicorp.com/terraform) is an infrastructure-as-code tool that enables developers and operations teams to define, manage, and provision cloud resources and infrastructure using declarative configuration files instead of manual setup.

With Terraform, you can describe infrastructure resources such as virtual machines, networks, and storage in code. Terraform then creates and manages these resources automatically. This approach makes infrastructure easier to version, review, and reproduce, helping teams maintain consistent environments across development, testing, and production.

Procedure: Install the Terraform and HCL plugin

This functionality relies on the [Terraform and HCL](https://plugins.jetbrains.com/plugin/7808-terraform-and-hcl)  plugin, which   you need to install and enable.

1. Press `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)) to open settings and then select `Plugins`.

2. Open the Marketplace tab, find the Terraform and HCL plugin, and click Install (restart the IDE if prompted).

Procedure: Specify the Terraform executable path

To run Terraform commands from the IDE using run configurations, you need to have Terraform installed on your machine.

1. Press `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)) to open settings and then select `Tools | Terraform Tools`.

2. In most cases, IntelliJ IDEA detects the path to the Terraform executable automatically. If the IDE does not detect the version and path to the executable, click Detect and Test.

If Terraform is not installed on your machine, click Install.

![Terraform Tools settings](https://resources.jetbrains.com/help/img/idea/2026.2/terraform_tools_settings.png)

3. If necessary, you can specify the path to Terraform manually in the Terraform executable path field.

> **Tip:**
> You can also specify a path in WSL:
>
>
>
>
> ```SHELL
> \\wsl$\<Distribution>\<path to Terraform>
> ```
>
>
>
> For example:
>
>
>
>
> ```SHELL
> \\wsl$\Ubuntu\usr\bin\terraform
> ```

## Create Terraform files

IntelliJ IDEA provides preconfigured templates for several Terraform file types. To create a file, in the Project tool window, right-click a directory and select `New | Terraform File`. This opens a dialog allowing you to choose from the available Terraform file templates.

![Terraform file type](https://resources.jetbrains.com/help/img/idea/2026.2/terraform_file_type.png)

| File extension | File template | Description |
| --- | --- | --- |
| `.tf` | Configuration | Terraform configuration file. |
| `.tfcomponent.hcl` | Component | Terraform component file. |
| `.tfdeploy.hcl` | Deployment | Terraform deployment file. |
| `.tftest.hcl` | Test | Terraform test file. |

> **Note:**
> Some Terraform file types do not have preconfigured file templates, but IntelliJ IDEA still provides coding assistance for them, including [syntax highlighting](#syntax-highlighting), [code completion](#completion), [navigation](#navigation), and more.

Terraform configurations often include multiple environments or interconnected components. You can organize setups as [Terraform workspaces](https://developer.hashicorp.com/terraform/language/state/workspaces) and [Terraform Stacks](https://developer.hashicorp.com/terraform/language/stacks), both of which are supported in IntelliJ IDEA.

### Terraform Stacks

[Terraform Stacks](https://developer.hashicorp.com/terraform/language/stacks) use the `.tfstack.hcl`, `.tfcomponent.hcl`, and `.tfdeploy.hcl` extensions.

IntelliJ IDEA provides coding assistance for Stack-specific constructs. The IDE offers completion for stack root blocks and their properties, automatically inserts required properties, and highlights missing required properties.

### Terraform Tests

IntelliJ IDEA supports the [Terraform Test Framework](https://developer.hashicorp.com/terraform/language/tests) for testing infrastructure code.

> **Note:**
> The testing framework is available in Terraform 1.6.0 and later.

IntelliJ IDEA recognizes and provides coding assistance for Terraform test files (`.tftest.hcl`) and reusable mock definitions that can be referenced from tests (`.tfmock.hcl`).

### Terraform template files

IntelliJ IDEA provides support for Terraform template files that typically use the `.tftpl` extension.

To use live templates, start typing `if` or `for` in a Terraform template file.

![Live templates](https://resources.jetbrains.com/help/img/idea/2026.2/terraform_template_live_template.png)

Procedure: Navigate to a template file

In a Terraform file, you can use the [templatefile](https://developer.hashicorp.com/terraform/language/functions/templatefile) function to inject a template. With IntelliJ IDEA, you can quickly navigate to the template file from your Terraform file.

1. In your Terraform file, locate the `templatefile` function.

2. Place the caret at the template file name and press `Ctrl+B` (Windows), `⌘ B` (macOS), `⌘ B` (IntelliJ IDEA Classic (macOS)), `⌘ B` (macOS System Shortcuts), `Ctrl+B` (XWin), `Ctrl+B` (GNOME), `Ctrl+B` (KDE), `Ctrl+Alt+G` (Emacs), `F12` (Sublime Text), `F12` (Sublime Text (macOS)), `Ctrl+B` (NetBeans), `F12` (Visual Studio), `F12` (Visual Studio (macOS)), `F3` (Eclipse), `F3` (Eclipse (macOS)).

Procedure: Select a template data language

If the language is specified in the template file extension (`file.<lang>.tftpl`), this language is used as a data language. For example, in `file.js.tftpl`, JavaScript will be used. If the data language is not specified (for example, `file.tftpl`), the template file is recognized as plain text.

You can select a data language (or change the detected one) if you want the file syntax to be recognized accordingly.

1. Right-click the file tab in the editor and select Change <Language> template data language to, for example, Change JavaScript template data language to or Change Plain text template data language to.

Alternatively, press `Alt+Enter` (Windows), `⌥ ⏎` (macOS), `⌥ ⏎` (IntelliJ IDEA Classic (macOS)), `⌥ ⏎` (macOS System Shortcuts), `Alt+Enter` (XWin), `Alt+Enter` (GNOME), `Alt+Enter` (KDE), `Alt+Enter` (Emacs), `Alt+Enter` (Sublime Text), `⌥ ⏎` (Sublime Text (macOS)), `Alt+Enter` (NetBeans), `Alt+Enter` (Visual Studio), `⌥ ⏎` (Visual Studio (macOS)), `Ctrl+1` (Eclipse), `⌘ 1` (Eclipse (macOS)) ( Show Context Actions ) in the file and select Choose template data language.

2. In the list of languages that opens, select the language.

### Terraform variables

Terraform variable definition files typically use the `.tfvars` extension. Use these files to provide values for variables declared in your Terraform configuration.

## Edit Terraform files

The IDE helps you stay productive by providing smart code insight for core Terraform elements and provider-defined concepts, allowing you to write infrastructure code faster and with fewer distractions. This includes the following features:

* [Syntax highlighting](configuring-colors-and-fonts.html) You can customize color settings in the Settings dialog (`Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS))), on the `Editor | Color Scheme | HCL` and `Editor | Color Scheme | HashiCorp Interpolation Language` pages.

* [Code completion](auto-completing-code.html) IntelliJ IDEA provides completion inside Terraform files, including known providers, provider functions, resources, data sources, actions, and arguments. ![Terraform resource completion](https://resources.jetbrains.com/help/img/idea/2026.2/terraform_completion.png) When configuring provider requirements, the IDE suggests available providers along with relevant attributes such as `source` and `version` in the `required_providers` block. This helps you define requirements according to the Terraform specification. For more details about provider requirements, refer to the [Terraform documentation](https://developer.hashicorp.com/terraform/language/providers/requirements). In Terraform Stacks files, IntelliJ IDEA offers completion for stack root blocks and their properties. Required properties are inserted automatically, and the IDE highlights any that are missing. In `.tfcomponent.hcl` files, IntelliJ IDEA supports completion for provider declarations and configuration, as well as module variables and providers used in `component` and `stack` blocks.

* [Full Line code completion](full-line-code-completion.html) Complete entire lines of code using a locally run deep learning model. ![Terraform Full Line code completion](https://resources.jetbrains.com/help/img/idea/2026.2/terraform_full_line_completion.animated.gif) You can disable Full-line code completion for Terraform in the Settings dialog (`Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS))) on the `Editor | General | Code Completion | Inline` page.

* [Code navigation](navigating-through-the-source-code.html) For resources, variables, locals, data sources, and Terraform actions IntelliJ IDEA shows the number of their usages in the form of inlay hints. Click the inlay hint (or press `Ctrl+B` (Windows), `⌘ B` (macOS), `⌘ B` (IntelliJ IDEA Classic (macOS)), `⌘ B` (macOS System Shortcuts), `Ctrl+B` (XWin), `Ctrl+B` (GNOME), `Ctrl+B` (KDE), `Ctrl+Alt+G` (Emacs), `F12` (Sublime Text), `F12` (Sublime Text (macOS)), `Ctrl+B` (NetBeans), `F12` (Visual Studio), `F12` (Visual Studio (macOS)), `F3` (Eclipse), `F3` (Eclipse (macOS))) to show all its usages and navigate to them. ![Terraform find usages](https://resources.jetbrains.com/help/img/idea/2026.2/terraform_usages_inlay_hints.png) You can disable, enable, and change the position of inlay hints for usages in the Settings dialog (`Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS))) under `Editor | Inlay Hints | Code vision | Usages`.

* [Refactorings](rename-refactorings.html) To rename the element and all its usages, press `Shift+F6` (Windows), `⇧ F6` (macOS), `⇧ F6` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ R` (macOS System Shortcuts), `Shift+F6` (XWin), `Shift+F6` (GNOME), `Shift+F6` (KDE), `Shift+F6` (Emacs), `Shift+F6` (Sublime Text), `⇧ F6` (Sublime Text (macOS)), `Ctrl+R` (NetBeans), `Ctrl+R, R` (Visual Studio), `⌘ R, R` (Visual Studio (macOS)), `Alt+Shift+R` (Eclipse), `⇧ F6` (Eclipse (macOS)).

* [Structure view](viewing-structure-of-a-source-file.html#structure-tool-window) Use the Structure tool window to quickly preview and navigate Terraform files. ![Terraform Structure](https://resources.jetbrains.com/help/img/idea/2026.2/terraform_structure.png) The tool window is available in `View | Tool Windows | Structure` or by pressing `Alt+7` (Windows), `⌘ 7` (macOS), `⌘ 7` (IntelliJ IDEA Classic (macOS)), `⌘ 7` (macOS System Shortcuts), `Alt+7` (XWin), `Alt+7` (GNOME), `Alt+7` (KDE), `Alt+7` (Emacs), `Alt+7` (Sublime Text), `⌘ 7` (Sublime Text (macOS)), `Ctrl+7` (NetBeans), `Ctrl+Alt+F` (Visual Studio), `⌃ ⌥ F` (Visual Studio (macOS)), `Alt+7` (Eclipse), `⌘ 7` (Eclipse (macOS)).

* [Quick documentation](viewing-reference-information.html#inline-quick-documentation) Hover over an argument to get quick documentation for it. ![Terraform quick documentation](https://resources.jetbrains.com/help/img/idea/2026.2/terraform_quick_documentation.png) For more details, you can also open Terraform Registry (which is the source of this documentation) by pressing `Shift+F1` (Windows), `⇧ F1` (macOS), `⇧ F1` (IntelliJ IDEA Classic (macOS)), `⇧ F1` (macOS System Shortcuts), `Shift+F1` (XWin), `Shift+F1` (GNOME), `Shift+F1` (KDE), `Shift+F1` (Emacs), `Shift+F1` (Sublime Text), `⇧ F1` (Sublime Text (macOS)), `Shift+F1` (NetBeans), `Shift+F1` (Visual Studio), `⇧ F1` (Visual Studio (macOS)), `Shift+F2` (Eclipse), `⇧ F2` (Eclipse (macOS)). > **Tip:** > The Terraform and HCL plugin comes with provider metadata of a specific version (you can see the version number when you start typing a resource name). If your provider version differs, and you want to show relevant quick documentation for it, you may need to perform `terraform init` to retrieve documentation for that specific version.

* [Code inspections](code-inspection.html) Using [Terraform inspections](https://www.jetbrains.com/help/inspectopedia/Terraform-OpenTofu.html), you can detect duplicate, conflicting, deprecated, or missing elements, unresolved references, unknown resources, and more. ![Terraform missing property inspection](https://resources.jetbrains.com/help/img/idea/2026.2/terraform_inspection_missing_argument.png) You can check all Terraform inspections in the Settings dialog (`Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS))) under `Editor | Inspections | Terraform`.

* Coding assistance also includes brace matching `Ctrl+Shift+M` (Windows), `⌃ M` (macOS), `⌘ ⇧ M` (IntelliJ IDEA Classic (macOS)), `⌃ M` (macOS System Shortcuts), `Ctrl+Shift+M` (XWin), `Ctrl+Shift+M` (GNOME), `Ctrl+Shift+M` (KDE), `Ctrl+Shift+M` (Emacs), `Ctrl+M` (Sublime Text), `⌃ M` (Sublime Text (macOS)), `Ctrl+Shift+M` (NetBeans), `Ctrl+]` (Visual Studio), `⌘ ]` (Visual Studio (macOS)), `Ctrl+Shift+P` (Eclipse), `⌃ M` (Eclipse (macOS)), code folding `Ctrl+NumPad +` (Windows), `⌘ NumPad +` (macOS), `⌘ NumPad +` (IntelliJ IDEA Classic (macOS)), `⌘ NumPad +` (macOS System Shortcuts), `Ctrl+NumPad +` (XWin), `Ctrl+NumPad +` (GNOME), `Ctrl+NumPad +` (KDE), `Ctrl+NumPad +` (Emacs), `Ctrl+Shift+]` (Sublime Text), `⌘ ⌥ ]` (Sublime Text (macOS)), `Ctrl+NumPad +` (NetBeans), `Ctrl+M, E` (Visual Studio), `⌃ M, E` (Visual Studio (macOS)), `Ctrl+NumPad +` (Eclipse), `⌘ NumPad +` (Eclipse (macOS)) / `Ctrl+NumPad -` (Windows), `⌘ NumPad -` (macOS), `⌘ NumPad -` (IntelliJ IDEA Classic (macOS)), `⌘ NumPad -` (macOS System Shortcuts), `Ctrl+NumPad -` (XWin), `Ctrl+NumPad -` (GNOME), `Ctrl+NumPad -` (KDE), `Ctrl+NumPad -` (Emacs), `Ctrl+Shift+[` (Sublime Text), `⌘ ⌥ [` (Sublime Text (macOS)), `Ctrl+NumPad -` (NetBeans), `Ctrl+M, S` (Visual Studio), `⌃ M, S` (Visual Studio (macOS)), `Ctrl+NumPad -` (Eclipse), `⌘ NumPad -` (Eclipse (macOS)), adding line comments `Ctrl+/` (Windows), `⌘ /` (macOS), `⌘ /` (IntelliJ IDEA Classic (macOS)), `⌘ /` (macOS System Shortcuts), `Ctrl+/` (XWin), `Ctrl+/` (GNOME), `Ctrl+/` (KDE), `Alt+;` (Emacs), `Ctrl+/` (Sublime Text), `⌘ /` (Sublime Text (macOS)), `Ctrl+/` (NetBeans), `Ctrl+Alt+/` (Visual Studio), `⌘ ⌥ /` (Visual Studio (macOS)), `Ctrl+/` (Eclipse), `⌘ /` (Eclipse (macOS)) and block comments `Ctrl+Shift+/` (Windows), `⌘ ⌥ /` (macOS), `⌃ ⇧ /` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ /` (macOS System Shortcuts), `Ctrl+Shift+/` (XWin), `Ctrl+Shift+/` (GNOME), `Ctrl+Shift+/` (KDE), `Ctrl+Shift+/` (Emacs), `Ctrl+Shift+/` (Sublime Text), `⌘ ⌥ /` (Sublime Text (macOS)), `Ctrl+Shift+/` (NetBeans), `Ctrl+Shift+/` (Visual Studio), `⌘ ⌃ /` (Visual Studio (macOS)), `Ctrl+Shift+/` (Eclipse), `⌘ ⇧ /` (Eclipse (macOS)), and [inserting copyright texts](copyright.html#paste-copyright) into your Terraform files.

## Run Terraform

The Terraform and HCL plugin provides dedicated run configurations for Terraform. These run configurations allow you to customize the execution of `terraform` commands, such as adding arguments or passing environment variables.

Procedure: Run Terraform using gutter icon

1. In a Terraform file, click ![Run](https://resources.jetbrains.com/help/img/idea/2026.2/app-client.expui.gutter.run.svg) in the gutter.

2. In the window that opens, select either Plan to create an execution plan or Apply if you already have a Terraform plan and want to apply it.

![Terraform run from gutter](https://resources.jetbrains.com/help/img/idea/2026.2/terraform_run.png)

If the Terraform initialization step was not performed for this directory, there will be a warning sign in the Run gutter icon. In this case, IntelliJ IDEA suggests you running the `terraform init` command before running `terraform plan` or `terraform apply`.

Running Terraform from the gutter icon creates a temporary run configuration. You can save it as a permanent one by clicking ![More Actions](https://resources.jetbrains.com/help/img/idea/2026.2/app-client.expui.general.moreVertical.svg) in the run widget and selecting Save Configuration.

Procedure: Create Terraform run configuration manually

1. Go to `Run | Edit Configurations`. Alternatively, press `Alt+Shift+F10` (Windows), `⌃ ⌥ R` (macOS), `⌥ ⇧ F10` (IntelliJ IDEA Classic (macOS)), `⌃ ⌥ R` (macOS System Shortcuts), `Alt+Shift+F10` (XWin), `Alt+Shift+F10` (GNOME), `Alt+Shift+F10` (KDE), `Alt+Shift+F10` (Emacs), `Alt+Shift+F10` (Sublime Text), `⌃ ⌥ R` (Sublime Text (macOS)), `Alt+Shift+F10` (NetBeans), `Ctrl+Alt+Shift+R` (Visual Studio), `⌘ ⌥ ⇧ R` (Visual Studio (macOS)), `Alt+Shift+F10` (Eclipse), `⌃ ⌥ R` (Eclipse (macOS)), then `0` (Windows), `0` (macOS), `0` (IntelliJ IDEA Classic (macOS)), `0` (macOS System Shortcuts), `0` (XWin), `0` (GNOME), `0` (KDE), `0` (Emacs), `0` (Sublime Text), `0` (Sublime Text (macOS)), `0` (NetBeans), `0` (Visual Studio), `0` (Visual Studio (macOS)), `0` (Eclipse), `0` (Eclipse (macOS)).

2. Click the Add New Configuration button (![Add a run/debug configuration](https://resources.jetbrains.com/help/img/idea/2026.2/app.expui.general.add.svg)) and start typing Terraform.

![Terraform run configuration](https://resources.jetbrains.com/help/img/idea/2026.2/terraform_run_configuration.png)

3. Select a type of the run configuration:

* Terraform Init to run `terraform init` commands

* Terraform Validate to run `terraform validate` commands

* Terraform Plan to run `terraform plan` commands

* Terraform Apply to run `terraform apply` commands

* Terraform Destroy to run `terraform destroy` commands

* Terraform, which lets you provide any other Terraform command

4. In the Command list, select a Terraform command. To run a command not included in this list, select Custom and specify it in the Program arguments field.

5. Give the run configuration a name and, if necessary, change the working directory. If you use environment variables, specify them in the Environment variables field or select a file to use variables from it.

## Reformat Terraform code

With IntelliJ IDEA, you can apply code style to your Terraform files. IntelliJ IDEA includes two formatting tools:

* [Terraform formatter](#use-terraform-formatter)

* [IntelliJ IDEA formatter](#use-jetbrains-formatter)

Procedure: Use Terraform formatter

The Terraform formatting tool (`terraform fmt`) is based on the [Terraform code
style](https://developer.hashicorp.com/terraform/language/style#code-formatting). It applies to `.tf` and `.tfvars` files.

The use of the Terraform formatting tool requires [Terraform
to be installed](#change-path-to-Terraform-executable).

* In the main menu, go to `Code | Terraform Tools | Format file`.

* Alternatively, press `Ctrl+Alt+Shift+F` (Windows), `⌘ ⌥ ⇧ F` (macOS), `⌘ ⌥ ⇧ F` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ ⇧ F` (macOS System Shortcuts), `Ctrl+Alt+Shift+F` (XWin), `Ctrl+Alt+Shift+F` (GNOME), `Ctrl+Alt+Shift+F` (KDE), `Ctrl+Alt+Shift+F` (Emacs), `Ctrl+Alt+Shift+F` (Sublime Text), `⌘ ⌥ ⇧ F` (Sublime Text (macOS)), `Ctrl+Alt+Shift+F` (NetBeans), `Ctrl+Alt+Shift+F` (Visual Studio), `⌘ ⌥ ⇧ F` (Visual Studio (macOS)), `Ctrl+Alt+Shift+F` (Eclipse), `⌘ ⌥ ⇧ F` (Eclipse (macOS)).

> **Tip:**
> If you also want to run the Terraform formatter when you invoke `Code | Reformat File`, you can configure IntelliJ IDEA to do so: Open the IDE settings (`Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS))), go to `Editor | Code Style | Terraform`, open the Other tab, and, under Terraform fmt, select On 'Reformat File' action.

While the Terraform formatter `terraform fmt` applies to an entire file, [IntelliJ IDEA formatter](#use-jetbrains-formatter) can also be applied to a selected piece of code.

Procedure: Use IntelliJ IDEA formatter

IntelliJ IDEA formatter is based on the IntelliJ IDEA [code style](reformat-and-rearrange-code.html)  provided by the Terraform and HCL plugin. You can customize this code style in the IDE settings, under `Editor | Code Style | Terraform`.

In addition to `.tf` and `.tfvars`, it also applies to `.hcl` files.

* To reformat a file, open it in the editor and, in the main menu, go to `Code | Reformat File`. Or press `Ctrl+Alt+Shift+L` (Windows), `⌘ ⌥ ⇧ L` (macOS), `⌘ ⌥ ⇧ L` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ ⇧ L` (macOS System Shortcuts), `Ctrl+Alt+Shift+L` (XWin), `Ctrl+Alt+Shift+L` (GNOME), `Ctrl+Alt+Shift+L` (KDE), `Ctrl+Alt+Shift+L` (Emacs), `Ctrl+Alt+Shift+L` (Sublime Text), `⌘ ⌥ ⇧ L` (Sublime Text (macOS)), `Ctrl+Alt+Shift+L` (NetBeans), `Ctrl+Alt+Shift+L` (Visual Studio), `⌘ ⌥ ⇧ L` (Visual Studio (macOS)), `Ctrl+Alt+Shift+L` (Eclipse), `⌘ ⌥ ⇧ L` (Eclipse (macOS)).

Alternatively,   in the Find Action… (`Ctrl+Shift+A` (Windows), `⌘ ⇧ A` (macOS), `⌘ ⇧ A` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ P` (macOS System Shortcuts), `Ctrl+Shift+A` (XWin), `Ctrl+Shift+A` (GNOME), `Ctrl+Shift+A` (KDE), `Escape, X` (Emacs), `Ctrl+Shift+P` (Sublime Text), `⌘ ⇧ P` (Sublime Text (macOS)), `Ctrl+I` (NetBeans), `Ctrl+Shift+A` (Visual Studio), `⌘ ⇧ A` (Visual Studio (macOS)), `Ctrl+Shift+A` (Eclipse), `⌘ 3` (Eclipse (macOS))) dialog, start typing `Reformat File`, then select the action from the list.

* To reformat part of the code, select a piece of code and, in the main menu, go to `Code | Reformat Code`. Or press `Ctrl+Alt+L` (Windows), `⌘ ⌥ L` (macOS), `⌘ ⌥ L` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ L` (macOS System Shortcuts), `Ctrl+Alt+L` (XWin), `Ctrl+Alt+L` (GNOME), `Alt+Shift+L` (KDE), `Ctrl+Alt+L` (Emacs), `Ctrl+Alt+L` (Sublime Text), `⌘ ⌥ L` (Sublime Text (macOS)), `Alt+Shift+F` (NetBeans), `Ctrl+Alt+Enter` (Visual Studio), `⌘ ⌥ ⏎` (Visual Studio (macOS)), `Ctrl+Alt+L` (Eclipse), `⌘ ⇧ F` (Eclipse (macOS)).

Alternatively,   in the Find Action… (`Ctrl+Shift+A` (Windows), `⌘ ⇧ A` (macOS), `⌘ ⇧ A` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ P` (macOS System Shortcuts), `Ctrl+Shift+A` (XWin), `Ctrl+Shift+A` (GNOME), `Ctrl+Shift+A` (KDE), `Escape, X` (Emacs), `Ctrl+Shift+P` (Sublime Text), `⌘ ⇧ P` (Sublime Text (macOS)), `Ctrl+I` (NetBeans), `Ctrl+Shift+A` (Visual Studio), `⌘ ⇧ A` (Visual Studio (macOS)), `Ctrl+Shift+A` (Eclipse), `⌘ 3` (Eclipse (macOS))) dialog, start typing `Reformat Code`, then select the action from the list.

## Refresh Terraform provider metadata

The Terraform and HCL plugin comes with provider metadata of a specific version, which enables coding assistance, such as completion for known properties and inspections.

If your project uses a different provider version (for example, after changing it in the `required_providers` block), initialize the project by running `terraform init`.

> **Tip: How to check if initialization is successful**
> * There are no warnings in the gutter of `.tf` files.
>
> * After running `terraform init`, the `.terraform/` directory and the `terraform.lock.hcl` file are added to the project root.

If the [Build local metadata
automatically](#build-local-metadata-automatically) option is enabled in `Settings | Advanced settings`, IntelliJ IDEA regenerates local provider metadata automatically. If the option is disabled, you can refresh the metadata manually.

Procedure: Refresh provider metadata manually

1. After initializing the project, do one of the following:

* Open a Terraform configuration file and right-click anywhere in the editor.

* Open the Project tool window (`Alt+1` (Windows), `⌘ 1` (macOS), `⌘ 1` (IntelliJ IDEA Classic (macOS)), `⌘ 1` (macOS System Shortcuts), `Alt+1` (XWin), `Alt+1` (GNOME), `Alt+1` (KDE), `Alt+1` (Emacs), `Alt+1` (Sublime Text), `⌘ 1` (Sublime Text (macOS)), `Ctrl+1` (NetBeans), `Ctrl+Alt+L` (Visual Studio), `⌘ ⌥ L` (Visual Studio (macOS)), `Alt+1` (Eclipse), `Alt+1` (Eclipse (macOS))) and right-click a Terraform configuration file.

2. From the context menu, select `Terraform Tools | Generate Providers Metadata`.

![The Generate Providers Metadata action](https://resources.jetbrains.com/help/img/idea/2026.2/terraform_generate_providers_metadata.png)

## Advanced settings

Download Terraform documentation automatically
: By default, IntelliJ IDEA downloads quick-documentation for Terraform properties from the Terraform Registry. In case you have network or performance issues, you can disable it, and IntelliJ IDEA will show descriptions from metadata instead. The availability of such descriptions depends on the resource developers.

Build local metadata automatically
: When enabled, IntelliJ IDEA regenerates local provider metadata automatically after you run `terraform init`. This ensures that coding assistance uses the provider versions defined in your configuration files.

Deep search for variables
: When you use variables in Terraform, IntelliJ IDEA checks all Terraform files in your project for the variable definition. Clear the checkbox if you want IntelliJ IDEA to check only files within the root directory (the one with `.terraform.lock.hcl`).

## Terraform code style settings

Terraform-specific code style settings are available in `Editor | Code Style | Terraform/OpenTofu | Other`.

Align properties while formatting
: Select the way to align properties and their values: align equal signs, align values, or do not align anything.

Line commenter symbol
: Select the symbol to be used for single-line comments when you press `Ctrl+/` (Windows), `⌘ /` (macOS), `⌘ /` (IntelliJ IDEA Classic (macOS)), `⌘ /` (macOS System Shortcuts), `Ctrl+/` (XWin), `Ctrl+/` (GNOME), `Ctrl+/` (KDE), `Alt+;` (Emacs), `Ctrl+/` (Sublime Text), `⌘ /` (Sublime Text (macOS)), `Ctrl+/` (NetBeans), `Ctrl+Alt+/` (Visual Studio), `⌘ ⌥ /` (Visual Studio (macOS)), `Ctrl+/` (Eclipse), `⌘ /` (Eclipse (macOS)).

Import providers automatically on completion
: Insert the provider requirements into the current file when you complete the resource name. Add the `required_providers` block if it's missing.

Invoke 'terraform/tofu fmt' for formatting
: Run the Terraform (or OpenTofu) formatter when you invoke `Code | Reformat File` .

