-->![G++ Is Not Recognized Visual Studio Code G++ Is Not Recognized Visual Studio Code](/uploads/1/1/8/1/118137253/829825665.png)
The Azure Terraform Visual Studio Code extension enables you to work with Terraform from the editor. With this extension, you can author, test, and run Terraform configurations. The extension also supports resource graph visualization.
In this article, you learn how to:
- Automate the provisioning of Azure services using Terraform
- install and use the Terraform Visual Studio Code extension for Azure services.
- Use Visual Studio Code to write, plan, and execute Terraform plans.
Prerequisites
- Azure subscription: If you don't have an Azure subscription, create a free account before you begin.
Navigate to the Debug view (Ctrl + Shift + D on Windows or Command + Shift + D on macOS) in the Activity Bar. If you do not have any configurations in Visual Studio Code, select F5 on Windows or macOS or select the green Play button. Select Edge in the dropdown. You should see a launch.json file with the following configuration. Git is not installed or selected As you can see from the image above, in the Output pane, there are standard paths where VS Code tries to look for a valid Git binary installation. This situation means that you either have to install Git first or maybe Git is installed but in a path that is not recognized by VS Code.
- Terraform: Install and configure Terraform.
- Visual Studio Code: Install the version of Visual Studio Code that is appropriate for your environment.
Prepare your dev environment
Install Git
To complete the exercises in the article, you need to install Git.
Install HashiCorp Terraform
Follow the instructions on the HashiCorp Install Terraform webpage, which covers:
- Downloading Terraform
- Installing Terraform
- Verifying Terraform is correctly installed
Tip
Visual Studio Mingw64
Be sure to follow the instructions regarding setting your PATH system variable.
Install Node.js
To use Terraform in the Cloud Shell, you need to install Node.js 6.0+.
Note
To verify if Node.js is installed, open a terminal window and enter
node -v
.Install GraphViz
To use the Terraform visualize function, you need to install GraphViz.
Note
Gcc Not Recognized
To verify if GraphViz is installed, open a terminal window and enter
dot -V
.Install the Azure Terraform Visual Studio Code extension
- Launch Visual Studio Code.
- Select Extensions.
- Use the Search Extensions in Marketplace text box to search for the Azure Terraform extension:
- Select Install.NoteWhen you select Install for the Azure Terraform extension, Visual Studio Code will automatically install the Azure Account extension. Azure Account is a dependency file for the Azure Terraform extension, which it uses to perform Azure subscription authentications and Azure-related code extensions.
Verify the Terraform extension is installed in Visual Studio Code
- Select Extensions.
- Enter
@installed
in the search text box.
The Azure Terraform extension will appear in the list of installed extensions.
You can now run all supported Terraform commands in your Cloud Shell environment from within Visual Studio Code.
Exercise 1: Basic Terraform commands walk-through
In this exercise, you create and execute a basic Terraform configuration file that provisions a new Azure resource group.
Prepare a test plan file
- In Visual Studio Code, select File > New File from the menu bar.
- In your browser, navigate to the Terraform azurerm_resource_group page and copy the code in the Example Usage code block:
- Paste the copied code into the new file you created in Visual Studio Code.NoteYou may change the name value of the resource group, but it must be unique to your Azure subscription.
- From the menu bar, select File > Save As.
- In the Save As dialog, navigate to a location of your choice and then select New folder. (Change the name of the new folder to something more descriptive than New folder.)NoteIn this example, the folder is named TERRAFORM-TEST-PLAN.
- Make sure your new folder is highlighted (selected) and then select Open.
- In the Save As dialog, change the default name of the file to main.tf.
- Select Save.
- In the menu bar, select File > Open Folder. Navigate to and select the new folder you created.
Run Terraform init command
- Launch Visual Studio Code.
- From the Visual Studio Code menu bar, select File > Open Folder... and locate and select your main.tf file.
- From the menu bar, select View > Command Palette... > Azure Terraform: Init.
- When the confirmation appears, select OK.
- The first time you launch Cloud Shell from a new folder, you're prompted to create a web application. Select Open.
- The Welcome to Azure Cloud Shell page opens. Select Bash or PowerShell.
- If you have not already set up an Azure storage account, the following screen appears. Select Create storage.
- Azure Cloud Shell launches in the shell you previously selected and displays information for the cloud drive it just created for you.
- You may now exit the Cloud Shell
- From the menu bar, select View > Command Palette > Azure Terraform: init.
Visualize the plan
![G++ Is Not Recognized Visual Studio Code G++ Is Not Recognized Visual Studio Code](/uploads/1/1/8/1/118137253/829825665.png)
Earlier in this article, you installed GraphViz. Terraform can use GraphViz to generate a visual representation of either a configuration or execution plan. The Azure Terraform Visual Studio Code extension implements this feature via the visualize command.
- From the menu bar, select View > Command Palette > Azure Terraform: Visualize.
Run Terraform plan command
The Terraform plan command is used to check whether the execution plan for a set of changes will do what you intended.
Note
Terraform plan does not make any changes to your real Azure resources. To actually make the changes contained in your plan, we use the Terraform apply command.
- From the menu bar, select View > Command Palette > Azure Terraform: plan.
Run Terraform apply command
After being satisfied with the results of Terraform plan, you can run the apply command.
- From the menu bar, select View > Command Palette > Azure Terraform: apply.
- Enter
yes
.
Verify your Terraform plan was executed
To see if your new Azure resource group was successfully created:
- Open the Azure portal.
- Select Resource groups in the left navigation pane.
Your new resource group should be listed in the NAME column.
Note
You may leave your Azure Portal window open for now; we will be using it in the next step.
Run Terraform destroy command
- From the menu bar, select View > Command Palette > Azure Terraform: destroy.
- Enter yes.
Verify your resource group was destroyed
To confirm that Terraform successfully destroyed your new resource group:
- Select Refresh on the Azure portal Resource groups page.
- Your resource group will no longer be listed.
Exercise 2: Terraform compute module
In this exercise, you learn how to load the Terraform compute module into the Visual Studio Code environment.
Clone the terraform-azurerm-compute module
- Use this link to access the Terraform Azure Rm Compute module on GitHub.
- Select Clone or download.NoteIn this example, our folder was named terraform-azurerm-compute.
Open the folder in Visual Studio Code
G++' Is Not Recognized As An Internal Or External Command Visual Studio Code
- Launch Visual Studio Code.
- From the menu bar, select File > Open Folder and navigate to and select the folder you created in the previous step.
Initialize Terraform
Before you can begin using the Terraform commands from within Visual Studio Code, you download the plug-ins for two Azure providers: random and azurerm.
- In the Terminal pane of the Visual Studio Code IDE, enter
terraform init
. - Enter
az login
, press <Enter, and follow the on-screen instructions.
Module test: lint
- From the menu bar, select View > Command Palette > Azure Terraform: Execute Test.
- From the list of test-type options, select lint.
- When the confirmation appears, select OK, and follow the on-screen instructions.
Note
When you execute either the lint or end to end test, Azure uses a container service to provision a test machine to perform the actual test. For this reason, your test results may typically take several minutes to be returned.
After a few moments, you see a listing in the Terminal pane similar to this example:
Test the module
- From the menu bar, select View > Command Palette > Azure Terraform: Execute Test.
- From the list of test type options, select end to end.
- When the confirmation appears, select OK, and follow the on-screen instructions.
Note
Visual Studio Code Mingw W64
When you execute either the lint or end to end test, Azure uses a container service to provision a test machine to perform the actual test. For this reason, your test results may typically take several minutes to be returned.
After a few moments, you see a listing in the Terminal pane similar to this example:
Troubleshooting
For Terraform-specific support, use one of HashiCorp's community support channels to Terraform:
- Questions, use-cases, and useful patterns: Terraform section of the HashiCorp community portal
- Provider-related questions: Terraform Providers section of the HashiCorp community portal