You can now use Terraform to write your infrastructure code and deploy it using release pipeline in Azure. The Terraform script is very basic script to show how easy it is to create any resource in Azure. You can download the script from here.

Assumption: The Virtual network, Subnet and resource group is already present in Azure. The Linux VM will be created with in existing resources. It will create public IP, Network Interface and VM.

Download/clone the github repo. There is VM.tf and variables.tf file. In Azure Devops it will look like this-

Set your variable values in “variables.tf” file. Set the existing resource group name, vmName, location, virtual network name, subnet name, vmSize, username and password.

No changes required in VM.tf file. It refers to variable values defined in variable.tf file.

Now create build pipeline and release pipeline as shown-

Build Pipeline-

Run the Build pipeline to create drop artifact as shown-

This artifact will be input for Release pipeline for deployment of resources (in this case creating Linux VM).

Release Pipeline:

 

Configure “Terraform Init”, “Terraform Plan” and “Terraform Apply” tasks. Make sure you mention the right Configuration Directory.

Once release pipeline is run, it will create the resource and show the results as below-