Terraform
Terraform is an open-source tool that enables developers and operations teams to define, manage, and provision cloud resources and infrastructure components with code as opposed to manual configuration through a cloud provider's UI.
With it, you manage infrastructure resources, such as virtual machines, networks, and storage, in a declarative and automated manner. The replacement of manual configuration with codified templates ensures consistent and reproducible infrastructure setups.
Install the Terraform and HCL plugin
This functionality relies on the Terraform and HCL plugin, which you need to install and enable.
Press Ctrl+Alt+S to open settings and then select
.Open the Marketplace tab, find the Terraform and HCL plugin, and click Install (restart the IDE if prompted).
GoLand provides the following features:
You can customize color settings in the Settings dialog (Ctrl+Alt+S) , on the and pages.
You can access code style settings related to Terraform in the Settings dialog (Ctrl+Alt+S) on the page.
Inspections
You can detect duplicate, conflicting, deprecated, or missing elements, unresolved references, and more.
You can check all Terraform inspections in the Settings dialog (Ctrl+Alt+S) under .
This includes completion for known providers, resources, data sources, and arguments.
Select a module or a variable and press Ctrl+B to navigate to its usages.
Refactorings
To rename the element and all its usages, press Shift+F6.
Structure view
Use the Structure tool window to quickly preview and navigate Terraform files.
The tool window is available in
or by pressing Alt+7.Hover over an argument to get quick documentation for it.
The window that pops up contains a link to Terraform Registry for more details. You can also open this link by pressing Shift+F1.
Coding assistance also includes brace matching Ctrl+Shift+M, code folding Ctrl+NumPad +/Ctrl+NumPad -, adding line comments Ctrl+/ and block comments Ctrl+Shift+/.
Specify path to Terraform executable
To run Terraform commands from the IDE (create execution plans and apply plans), Terraform must be installed on your computer.
In most cases, GoLand detects the Terraform installation path. If it is not the case or if the path is detected incorrectly, you can specify it manually.
Press Ctrl+Alt+S to open settings and then select
.In the Terraform executable path field, specify the path to Terraform.
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.
Run Terraform using gutter icon
In a Terraform file, click in the gutter.
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.
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, GoLand 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 in the run widget and selecting Save Configuration.
Create Terraform run configuration manually
Go to
. Alternatively, press Alt+Shift+F10, then 0.Click the Add New Configuration button () and start typing Terraform.
Select a type of the run configuration:
Terraform Plan to run
terraform plan
commandsTerraform Apply to run
terraform apply
commandsTerraform, which lets you provide any other Terraform command
Give the run configuration a name and, if necessary, change the working directory and provide environment variables.
Terraform template files
GoLand provides support for Terraform template files that typically use the .tftpl
extension. Support for template files includes coding assistance (syntax highlighting, inspections, and more), navigation to template files, and live templates.
To use live templates, start typing if
or for
in a Terraform template file.
Navigate to template file
In a Terraform file, you can use the templatefile function to inject a template. With GoLand, you can quickly navigate to the template file from your Terraform file.
In your Terraform file, locate the
templatefile
function.Place the caret at the template file name and press Ctrl+B.
Select template data language
By default, template files are recognized as plain text. You can change it to another supported programming language if you want the file syntax to be recognized accordingly.
Right-click the file tab in the editor and select Change Plain text template data language to.
Alternatively, press Alt+Enter (Show Context Actions) and select Choose template data language.
In the list of languages that opens, select the language.