The VSCode Microsoft Terraform extension is designed to increase developer productivity authoring, testing and using Terraform with Azure. The extension provides terraform command support and resource graph visualization.
This extension requires:
NOTE: Please make sure these requirements are in your PATH environment variable.
This extension supports the following features:
- Terraform commands: init, plan, apply, validate, refresh and destroy
- Visualize the terraform module
- Suggest resources, properties, and values for those properties
- On-hover documentation
- Integration with Azure Export for Terraform to Export Azure Resources As Terraform Blocks
- Integrated survey for user feedback
This extension provides the following guides to help you get started:
- Input
azurerm_
in a.tf
file to see example suggestions forazurerm
resources.
- Hover over an
azurerm
resource or property to see its documentation.
- It provides value suggestions for properties of
azurerm
resources. For example, if you typesku_name =
, it will suggest available values for thesku_name
property of theazurerm_automation_account
resource.
Completion of allowed azure resource types when input type
in azapi
resources
Completion of allowed azure resource properties when input body
in azapi
resources
Completion of required properties for any discriminated objects.
Show hint when hover on azapi
resources and diagnostics to indicate schema errors as you type.
Paste resource JSON to the terraform configuration, it will convert to azapi configuration.
Paste ARM template to the terraform configuration, it will convert to azapi configuration.
Migrate from AzureRM provider to AzApi provider. More details can be found in Guide to migrate AzureRM resources to AzAPi in Module
This feature allows you to export existing Azure resources as Terraform configuration blocks using Azure Export for Terraform. This helps you migrate existing Azure resources to Terraform-managed infrastructure.
-
Open the Command Palette (
Command
+Shift
+P
on macOS andCtrl
+Shift
+P
on Windows/Linux). -
Search for and select the command
Microsoft Terraform: Export Azure Resource as Terraform
. -
Follow the prompts to select the Azure subscription and resource group containing the resources you want to export.
-
Select the
azurerm
provider or theazapi
provider to export the resources. -
The extension will generate the Terraform configuration blocks for the selected resources and display them in a new editor tab.
This feature help you generate the required permissions for AzureRM resources in Terraform configuration.
Select some azurerm
resources in your .tf
file, then you can see a lightbulb icon appear next to the selected resources. Click on the lightbulb icon to see the option to generate required permissions. After clicking, the extension will generate the required permissions and display them in a new editor tab.
This feature also supports generating the missing permissions for the selected resources. Please ensure that you have logged in to Azure using the az login
command before using this feature.
A step-by-step guide can be found here.
Preflight validation helps you identify potential issues in your Terraform configuration before deployment by analyzing your Terraform plan. This feature uses the aztfpreflight
tool to validate your infrastructure changes.
To use preflight validation:
-
Ensure you have a valid Terraform configuration in your workspace.
-
Open the Command Palette (
Command
+Shift
+P
on macOS andCtrl
+Shift
+P
on Windows/Linux). -
Search for and select the command
Microsoft Terraform: Preflight Validation
. -
The extension will prompt you to either:
- Select an existing Terraform plan file, or
- Generate a new plan file
-
If you choose to generate a new plan file:
- Ensure you're authenticated to Azure using
az login
command
- Ensure you're authenticated to Azure using
-
The extension will:
- Generate a Terraform plan for your configuration
- Run preflight validation against the generated plan
- Display the validation results in the terminal
The validation results will help you identify potential issues such as:
- Azure resource configuration validation
- Pre-deployment infrastructure checks
- Policy compliance verification
- Resource provisioning constraints
Note: Preflight validation runs locally in the integrated terminal and requires an active Azure authentication session.
We value your feedback! You can share your experience with the Microsoft Terraform extension by running the command Microsoft Terraform: Show Survey
from the Command Palette. Your input helps us improve the extension and better serve your needs.
Open the Command Palette (Command
+Shift
+P
on macOS and Ctrl
+Shift
+P
on Windows/Linux) and type in one of the following commands:
Command | Description |
---|---|
Basic commands:
|
Execute terraform command against the current project workspace.
Note: All commands run in your local integrated terminal. |
Microsoft Terraform: visualize | Create a visual representation of the components of the module and save it in graph.png . |
Microsoft Terraform: Execute Test |
Run one of the following test against the current module using a test container:
|
Microsoft Terraform: Export Azure Resource as Terraform | Export existing Azure resources as Terraform configuration blocks using Azure Export for Terraform. This helps you migrate existing Azure resources to Terraform-managed infrastructure. |
Microsoft Terraform: Show Survey | Open the feedback survey to share your experience and help us improve. |
Microsoft Terraform: Preflight Validation | Run preflight validation against your Terraform plan to identify potential issues before deployment. This command generates a Terraform plan and validates it using the aztfpreflight tool. |
azureTerraform.terminal
- Specifies terminal used to run Terraform commands. Currently onlyintegrated
terminal is supported.azureTerraform.test.imageName
- Indicates the container to use to run the tests. By default:microsoft/terraform-test
.azureTerraform.test.aciName
- Indicates the name of the Azure Container Instance to use for testing. By default:tf-test-aci
.azureTerraform.test.aciResourceGroup
- Indicates the name of the Resource Group to use for the ACI instance. By default:tfTestResourceGroup
.azureTerraform.aciContainerGroup
- Indicates the name of the Container Group that host the ACI instance. By default:tfTestContainerGroup
azureTerraform.test.location
- Indicates the location where to deploy the test container instance. By default:westus
.
Refer to CHANGELOG
VS Code collects usage data and sends it to Microsoft to help improve our products and services. Read our privacy statement to learn more. If you would like to opt out of sending telemetry data to Microsoft, update the telemetry.enableTelemetry
setting to false
in the File -> Preferences -> Settings. Read our FAQ to learn more.