KEMBAR78
Install The Azure Terraform Visual Studio Code Extension | PDF | Microsoft Azure | Command Line Interface
0% found this document useful (0 votes)
11 views7 pages

Install The Azure Terraform Visual Studio Code Extension

The document provides a guide on installing and using the Azure Terraform Visual Studio Code extension to define, preview, and deploy cloud infrastructure. It outlines steps for configuring the environment, installing the extension, implementing Terraform code, and managing Azure resources. Additionally, it includes instructions for creating and verifying a resource group, as well as cleaning up resources after testing.

Uploaded by

Shailesh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views7 pages

Install The Azure Terraform Visual Studio Code Extension

The document provides a guide on installing and using the Azure Terraform Visual Studio Code extension to define, preview, and deploy cloud infrastructure. It outlines steps for configuring the environment, installing the extension, implementing Terraform code, and managing Azure resources. Additionally, it includes instructions for creating and verifying a resource group, as well as cleaning up resources after testing.

Uploaded by

Shailesh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

7/19/25, 9:28 AM Install the Azure Terraform Visual Studio Code extension | Microsoft Learn

Install the Azure Terraform Visual Studio


Code extension
05/10/2023

Terraform enables the definition, preview, and deployment of cloud infrastructure. Using
Terraform, you create configuration files using HCL syntax . The HCL syntax allows you to
specify the cloud provider - such as Azure - and the elements that make up your cloud
infrastructure. After you create your configuration files, you create an execution plan that
allows you to preview your infrastructure changes before they're deployed. Once you verify the
changes, you apply the execution plan to deploy the infrastructure.

The Visual Studio Code Terraform extension enables you to work with Terraform from the
editor. With this extension, you can author, test, and run Terraform configurations.

In this article, you learn how to:

" Install the Azure Terraform Visual Studio Code extension


" Use the extension to create an Azure resource group
" Verify the resource group was created
" Delete the resource group when finished testing using the extension

1. Configure your environment


Azure subscription: If you don't have an Azure subscription, create a free account
before you begin.

Configure Terraform: If you haven't already done so, configure Terraform using one of
the following options:
Configure Terraform in Azure Cloud Shell with Bash
Configure Terraform in Azure Cloud Shell with PowerShell
Configure Terraform in Windows with Bash
Configure Terraform in Windows with PowerShell

Install Node.js .

2. Install the Azure Terraform Visual Studio Code


extension
1. Launch Visual Studio Code.

https://learn.microsoft.com/en-us/azure/developer/terraform/configure-vs-code-extension-for-terraform?tabs=azure-cli 1/7
7/19/25, 9:28 AM Install the Azure Terraform Visual Studio Code extension | Microsoft Learn

2. From the left menu, select Extensions, and enter Azure Terraform in the search text box.

3. From the list of extensions, locate the Azure Terraform extension. (It should be the first
extension listed.)

4. If the extension isn't yet installed, select the extension's Install option.

Key points:

When you select Install for the Azure Terraform extension, Visual Studio Code
automatically installs the Azure Account extension.
Azure Account is a dependency file for the Azure Terraform extension. This file is
used to authenticate to Azure and Azure-related code extensions.

5. To confirm the installation of the extensions, enter @installed in the search text box.
Both the Azure Terraform extension and the Azure Account extension appear in the list of
installed extensions.

https://learn.microsoft.com/en-us/azure/developer/terraform/configure-vs-code-extension-for-terraform?tabs=azure-cli 2/7
7/19/25, 9:28 AM Install the Azure Terraform Visual Studio Code extension | Microsoft Learn

You can now run all supported Terraform commands in your Cloud Shell environment from
within Visual Studio Code.

3. Implement the Terraform code


1. Create a directory in which to test the sample Terraform code and make it the current
directory.

2. Create a file named providers.tf and insert the following code:

Terraform

terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~>4.0"
}
random = {
source = "hashicorp/random"
version = "~>3.0"
}
https://learn.microsoft.com/en-us/azure/developer/terraform/configure-vs-code-extension-for-terraform?tabs=azure-cli 3/7
7/19/25, 9:28 AM Install the Azure Terraform Visual Studio Code extension | Microsoft Learn
}
}

provider "azurerm" {
features {}
}

3. Create a file named main.tf and insert the following code:

Terraform

# Create a random name for the resource group using random_pet


resource "random_pet" "rg_name" {
prefix = var.resource_group_name_prefix
}

# Create a resource group using the generated random name


resource "azurerm_resource_group" "example" {
location = var.resource_group_location
name = random_pet.rg_name.id
}

4. Create a file named variables.tf to contain the project variables and insert the following
code:

Terraform

variable "resource_group_location" {
type = string
default = "eastus"
description = "Location of the resource group."
}

variable "resource_group_name_prefix" {
type = string
default = "rg"
description = "Prefix of the resource group name that's combined with a
random ID so name is unique in your Azure subscription."
}

5. Create a file named outputs.tf to contain the project variables and insert the following
code:

Terraform

output "resource_group_name" {
value = azurerm_resource_group.example.name
}

https://learn.microsoft.com/en-us/azure/developer/terraform/configure-vs-code-extension-for-terraform?tabs=azure-cli 4/7
7/19/25, 9:28 AM Install the Azure Terraform Visual Studio Code extension | Microsoft Learn

4. Push your code to Cloud Shell


1. From the View menu, select Command Palette....

2. In the Command Palette text box, start entering Azure Terraform: Push and select it
when it displays.

3. Select OK to confirm the opening of Cloud Shell.

Key points:

Your workspace files that meet the filter defined in the azureTerraform.files setting
in your configuration are copied to Cloud Shell.

5. Initialize Terraform within Visual Studio Code


1. From the View menu, select Command Palette....

2. In the Command Palette text box, start entering Azure Terraform: Init and select it
when it displays.

Key points:

Selecting this option is the same as running terraform init from the command line
and initializes your Terraform deployment.
This command downloads the Azure modules required to create an Azure resource
group.

3. Follow the prompts to install any dependencies - such as the latest supported version of
nodejs.

4. If you're using Cloud Shell for the first time with your default Azure subscription, follow
the prompts to configure the environment.

6. Create a Terraform execution plan within Visual


Studio Code
https://learn.microsoft.com/en-us/azure/developer/terraform/configure-vs-code-extension-for-terraform?tabs=azure-cli 5/7
7/19/25, 9:28 AM Install the Azure Terraform Visual Studio Code extension | Microsoft Learn

1. From the View menu, select Command Palette....

2. In the Command Palette text box, start entering Azure Terraform: Plan and select it
when it displays.

Key points:

This command runs terraform plan to create an execution plan from the
Terraform configuration files in the current directory.

7. Apply a Terraform execution plan within Visual


Studio Code
1. From the View menu, select Command Palette....

2. In the Command Palette text box, start entering Azure Terraform: Apply and select it
when it displays.

3. When prompted for confirmation, enter yes and press <Enter> .

8. Verify the results


Azure CLI

1. From the View menu, select Command Palette....

2. In the Command Palette text box, start entering Azure: Open Bash in Cloud Shell
and select it when it displays.

3. Run az group show to display the resource group. Replace the


<resource_group_name> placeholder with the randomly generated name of the

resource group displayed after applying the Terraform execution plan.

Azure CLI

az group show --name <resource_group_name>

9. Clean up resources
1. From the View menu, select Command Palette....
https://learn.microsoft.com/en-us/azure/developer/terraform/configure-vs-code-extension-for-terraform?tabs=azure-cli 6/7
7/19/25, 9:28 AM Install the Azure Terraform Visual Studio Code extension | Microsoft Learn

2. In the Command Palette text box, start entering Azure Terraform: Destroy and select it
when it displays.

3. When prompted for confirmation, enter yes and press <Enter> .

4. To confirm that Terraform successfully destroyed your new resource group, run the steps
in the section, Verify the results.

Troubleshoot Terraform on Azure


Troubleshoot common problems when using Terraform on Azure

Next steps
Read more about the Azure Terraform Visual Studio Code extension

https://learn.microsoft.com/en-us/azure/developer/terraform/configure-vs-code-extension-for-terraform?tabs=azure-cli 7/7

You might also like