Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The Microsoft Terraform Visual Studio Code extension provides authoring, validation, and migration tooling for Terraform configurations on Azure. It includes language intelligence for both the AzureRM and AzAPI providers, integration with Azure Export for Terraform (aztfexport), and preflight validation support.
This article covers the features most relevant to AzAPI authoring and provider migration. For a guide to installing the extension and running basic Terraform commands, see Install the Microsoft Terraform Visual Studio Code extension.
Prerequisites
- Visual Studio Code
- The Microsoft Terraform extension installed
- Terraform installed and available in your PATH
- The Azure CLI installed and authenticated (
az login)
AzAPI provider language features
Use this when: You're authoring or editing azapi_resource blocks and want autocomplete, validation, and inline documentation.
The extension provides rich language intelligence for the AzAPI provider in .tf files, backed by the AzAPI Language Server.
Resource type and API version completion
When you type type = " inside an azapi_resource, azapi_update_resource, or azapi_data_plane_resource block, the extension shows a list of all available Azure resource types and API versions:
Property name and value completion
Inside the body attribute, the extension suggests allowed property names and valid values based on the selected resource type and API version:
For properties that use discriminated objects (such as kind-based type hierarchies), the extension populates required sub-properties automatically.
Hover documentation
Hovering over a resource type, property name, or property value shows inline documentation sourced from the Azure resource schema:
Schema validation
The extension underlines schema errors as you type — for example, unrecognized property names, incorrect value types, or missing required properties:
Paste ARM JSON as AzAPI configuration
If you have an Azure portal resource definition, an ARM template resource object, or a raw REST API response, you can paste it directly into a .tf file and the extension converts it to an azapi_resource block.
Use this when: You're authoring a new AzAPI resource and have an existing JSON definition to start from.
- Copy the resource JSON or ARM template to the clipboard.
- Open a
.tffile and place your cursor at the insertion point. - Paste (
Ctrl+Von Windows/Linux,Cmd+Von macOS). The extension detects the JSON format and converts it toazapi_resourceHCL.
For ARM templates that contain multiple resources, parameters, and variables, manual cleanup is usually required after conversion. Review the generated type, body, and parent_id before applying.
Export existing Azure resources as Terraform
The extension integrates with aztfexport to export existing Azure resources to Terraform configuration and state, with a choice of AzureRM or AzAPI as the output provider.
Use this when: You have existing Azure resources that aren't managed by Terraform and want to bring them under Terraform management.
- Open the Command Palette (
Ctrl+Shift+Pon Windows/Linux,Cmd+Shift+Pon macOS). - Search for and select Microsoft Terraform: Export Azure Resource as Terraform.
- Follow the prompts to select your subscription, resource group, and individual resources.
- Select azurerm or azapi as the output provider.
- The extension generates the Terraform configuration and opens it in a new editor tab.
You can also export resources directly from the Azure portal without installing any tools. See Export a resource in the Azure portal. For full CLI usage of aztfexport, see the Azure Export for Terraform overview.
Migrate AzureRM resources to AzAPI
The extension can generate AzAPI equivalents for azurerm_* resource blocks within a Terraform module, using guidance from the azapi-lsp migration guide.
Use this when: You're converting a module from AzureRM to AzAPI and want tooling assistance to author the equivalent azapi_resource blocks.
- Open the
.tffile containing theazurerm_*resource blocks. - Open the Command Palette and search for the migrate to AzAPI command, or use the in-editor code action when hovering over an
azurerm_*resource block. - Review the generated output. Validate the
type,api-version, andbodystructure against the AzAPI provider registry documentation before replacing the original blocks.
Important
This feature assists with HCL authoring only — it doesn't update the Terraform state file. If you replace azurerm_* blocks with azapi_resource blocks without updating state, Terraform treats the AzureRM resources as deleted and the AzAPI resources as new, causing re-creation of the underlying Azure resources.
To migrate state alongside configuration, use terraform state mv for each resource after conversion, or add import blocks. Run terraform plan after each state change to confirm no unintended re-creation occurs.
For a complete guide covering all migration directions (including aztfmigrate for AzAPI → AzureRM), see Migration paths between Azure, AzureRM, and AzAPI Terraform providers.
Preflight validation
The extension integrates with the aztfpreflight tool to validate your Terraform plan against Azure resource constraints before deployment.
Use this when: You want to catch configuration errors at plan time without deploying resources.
- Ensure you're authenticated with
az login. - Open the Command Palette and select Microsoft Terraform: Preflight Validation.
- Select an existing plan file, or let the extension generate a new one.
- The extension runs
aztfpreflightagainst the plan and displays results in the terminal.
Preflight catches errors such as invalid property values, quota violations, and policy compliance failures before any resources are created or modified. For details on enabling preflight directly in the AzAPI provider configuration, see Enable preflight validation in the AzAPI Terraform provider.
Generate required permissions
Use this when: You need to determine the minimum IAM role assignments required to deploy your Terraform resources.
For azurerm_* resource blocks, the extension can generate the minimum IAM role assignments needed to deploy the resources.
- Select one or more
azurerm_*resource blocks in a.tffile. - Click the lightbulb icon that appears, and select the option to generate required permissions.
- The extension generates the permission definitions and opens them in a new editor tab.
Ensure you're authenticated with az login before using this feature.
Terraform command palette
All standard Terraform commands are available from the Command Palette and run in the integrated terminal:
| Command | Description |
|---|---|
| Microsoft Terraform: init | Initializes the Terraform working directory and downloads provider plugins. |
| Microsoft Terraform: plan | Creates a Terraform execution plan. |
| Microsoft Terraform: apply | Applies the Terraform execution plan. |
| Microsoft Terraform: validate | Validates the configuration files. |
| Microsoft Terraform: refresh | Updates the state file with the real-world state of resources. |
| Microsoft Terraform: destroy | Destroys all resources managed by the configuration. |
| Microsoft Terraform: visualize | Generates a graph visualization of the module and saves it as graph.png. |
| Microsoft Terraform: Export Azure Resource as Terraform | Exports existing Azure resources as Terraform configuration using aztfexport. |
| Microsoft Terraform: Preflight Validation | Runs preflight validation against a Terraform plan using aztfpreflight. |