Solution Idea
- Visual Studio Free Download
- Visual Studio Code Remote Terraform
- Visual Studio Download
- Terraform Editor
If you'd like to see us expand this article with more information, implementation details, pricing guidance, or code examples, let us know with GitHub Feedback!
Visual Studio Code: Build and deploy multi-platform apps to get the most from Azure services. Use Terraform to create a Virtual Machine Scale Set from a Packer customer VM image; Use Terraform to plan and create a Virtual Machine Scale Set with Managed Disk; Use Log Analytics to collect data from Linux computers. Terraform Tools. Install and execute terraform as part of your build & release pipelines. Downloads & installs specified version of Terraform and adds it to the tool cache. The Terraform AWS provider is a plugin for Terraform that allows for the full lifecycle management of AWS resources. This provider is maintained internally by the HashiCorp AWS Provider team. Please note: We take Terraform's security and our users' trust very seriously. 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.

Azure is a world-class cloud for hosting virtual machines running Windows or Linux. Whether you use Java, Node.js, Go, or PHP to develop your applications, you'll need a continuous integration and continuous deployment (CI/CD) pipeline to push changes to these virtual machines automatically.
Architecture
Download an SVG of this architecture.
Data Flow
- Change application source code.
- Commit code to GitHub.
- Continuous Integration Trigger to Jenkins.
- Jenkins triggers a Packer image build to create a VM and stores it as a VM image using Azure Managed Disks.
- Jenkins triggers Terraform to provision a new Virtual Machine Scale Set using the Azure Managed Disks VM image.
- Azure Log Analytics collects and analyzes logs.
- Monitor application and make improvements.
Components
- Managed Disks: Persistent, secured disk storage for Azure virtual machines.
- Virtual Machine Scale Sets: Manage and scale up to thousands of Linux and Windows virtual machines.
- Log Analytics: Collect, search, and visualize machine data from on-premises and cloud.
- Visual Studio Code: Build and deploy multi-platform apps to get the most from Azure services.
Next steps
Deploy to Azure
-->In this article, you'll learn how to use the combination of Terraform and Yeoman. Terraform is a tool for creating infrastructure on Azure. Yeoman makes it easy to create Terraform modules.
In this article, you learn how to do the following tasks:
- Create a base Terraform template using the Yeoman module generator.
- Test the Terraform template using two different methods.
- Run the Terraform module using a Docker file.
- Run the Terraform module natively in Azure Cloud Shell.

Prerequisites
- Azure subscription: If you don't have an Azure subscription, create a free account before you begin.
- Visual Studio Code: Download Visual Studio Code for your platform.
- Terraform: Install Terraform to run the module created by Yeoman.
- Docker: Install Docker to run the module created by the Yeoman generator.
- Go programming language: Install Go as Yeoman-generated test cases are code using the Go language.
Note
Most of the procedures in this article involve the command line interface. The steps described apply to all operating systems and command line tools. For the examples, PowerShell was chosen for the local environment and Git Bash for the cloud shell environment.
Prepare your environment
Install Node.js
To use Terraform in the Cloud Shell, you need to install Node.js 6.0+.
Note
To verify that Node.js is installed, open a terminal window and enter node --version
.
Install Yeoman
Run the following command:
Install the Yeoman template for Terraform module
Run the following command:
To verify that Yeoman is installed, run the following command:
Create a directory for the Yeoman-generated module
The Yeoman template generates files in the current directory. For this reason, you need to create a directory.
This empty directory is required to be put under $GOPATH/src. For more information about this path, see the article Setting GOPATH.
Navigate to the parent directory from which to create a new directory.
Run the following command replacing the placeholder. For this example, a directory name of
GeneratorDocSample
is used.Navigate to the new directory:
Create a base module template
Run the following command:
Follow the on-screen instructions to provide the following information:
Terraform module project Name - A value of
doc-sample-module
is used for the example.Would you like to include the Docker image file? - Enter
y
. If you entern
, the generated module code will support running only in native mode.
List the directory contents to view the resulting files that are created:
Review the generated module code
Visual Studio Free Download
Launch Visual Studio Code
From the menu bar, select File > Open Folder and select the folder you created.
The following files were created by the Yeoman module generator:
main.tf
- Defines a module calledrandom-shuffle
. The input is astring_list
. The output is the count of the permutations.variables.tf
- Defines the input and output variables used by the module.outputs.tf
- Defines what the module outputs. Here, it's the value returned byrandom_shuffle
, which is a built-in, Terraform module.Rakefile
- Defines the build steps. These steps include:build
- Validates the formatting of the main.tf file.unit
- The generated module skeleton doesn't include code for a unit test. If you want to specify a unit test scenario, you would you add that code here.e2e
- Runs an end-to-end test of the module.
test
- Test cases are written in Go.
- All codes in test are end-to-end tests.
- End-to-end tests attempt to provision all of the items defined under
fixture
. The results in thetemplate_output.go
file are compared with the pre-defined expected values. Gopkg.lock
andGopkg.toml
: Defines the dependencies.
For more information about the Yeoman generator for Azure https://github.com/Azure/generator-az-terra-module, see the Terratest documentation.
Test your new Terraform module using a Docker file
This section shows how to test a Terraform module using a Docker file.
Note
This example runs the module locally; not on Azure.
Confirm Docker is installed and running
From a command prompt, enter docker version
.
The resulting output confirms that Docker is installed.
To confirm that Docker is actually running, enter docker info
.
Set up a Docker container
From a command prompt, enter
docker build --build-arg BUILD_ARM_SUBSCRIPTION_ID= --build-arg BUILD_ARM_CLIENT_ID= --build-arg BUILD_ARM_CLIENT_SECRET= --build-arg BUILD_ARM_TENANT_ID= -t terra-mod-example .
.The message Successfully built will be displayed.
From the command prompt, enter
docker image ls
to see your created moduleterra-mod-example
listed.Enter
docker run -it terra-mod-example /bin/sh
. After running thedocker run
command, you're in the Docker environment. At that point, you can discover the file by using thels
command.
Build the module
Visual Studio Code Remote Terraform
Run the following command:
Run the following command:
Run the end-to-end test
Run the following command:
After a few moments, the PASS message will appear.
Enter
exit
to complete the test and exit the Docker environment.
Use Yeoman generator to create and test a module in Cloud Shell
In this section, the Yeoman generator is used to create and test a module in Cloud Shell. Using Cloud Shell instead of using a Docker file greatly simplifies the process. Using Cloud Shell, the following products are all pre-installed:
- Node.js
- Yeoman
- Terraform
Start a Cloud Shell session
Start an Azure Cloud Shell session via either the Azure portal, shell.azure.com, or the Azure mobile app.
The Welcome to Azure Cloud Shell page opens. Select Bash (Linux).
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.

Prepare a directory to hold your Terraform module
At this point, Cloud Shell will have already configured GOPATH in your environment variables for you. To see the path, enter
go env
.Create the $GOPATH directory, if one doesn't already exist: Enter
mkdir ~/go
.Create a directory within the $GOPATH directory. This directory is used to hold the different project directories created in this example.
Create a directory to hold your Terraform module replacing the placeholder. For this example, a directory name of
my-module-name
is used.Navigate to your module directory:
Create and test your Terraform module
Run the following command and follow the instructions. When asked if you want to create the Docker files, you enter
N
.Run the following command to install the dependencies:
Run the following command to build the module:
Run the following command to run the test:
Troubleshooting
For Terraform-specific support, use one of HashiCorp's community support channels to Terraform:
Visual Studio Download
- Questions, use-cases, and useful patterns: Terraform section of the HashiCorp community portal
- Provider-related questions: Terraform Providers section of the HashiCorp community portal
Next steps
Terraform Editor
Install and use the Azure Terraform Visual Studio Code extension.
