Open source tools, like Terraform and Ansible, can be leveraged to implement “infrastructure as code,” making it easier to continuously build and deploy cloud infrastructure across your applications.
Visual Studio Team Services (VSTS) provides automated pipelines to build, test, and deploy your code to any platform. It uses agents to perform build and release tasks. Creating private agents has the advantage of being able to install the specific software needed for the builds.
To use HashiCorp and Ansible tools for Azure build and release tasks, we will configure a private VSTS agent with a prepared image hosted on DockerHub). This image is based on the Microsoft standard VSTS agent image and extends it with installed Terraform, Packer and Ansible tools.
To make your solution more lightweight and to minimize costs for running the agent, we’ll show you how to provision a custom VSTS agent on Azure Container Instance (ACI) — a service that became generally available this month. ACI provides an easy way to run containers on Azure.
VSTS Agent Pool
First, create an Agent Pool in your VSTS account named “ACI-Pool” — it will be used by agent registration. To learn more about deploying agents and getting PAT token configuration, refer to our “Deploy an agent on Linux” documentation.
VSTS Docker Image with Infrastructure Tools
For the pipeline in this post, we built and published at DockerHub an image based on the Microsoft VSTS agent with all the tools (Packer, Terraform, Ansible) pre-installed. For details on the installed tools and Dockerfile refer to: https://hub.docker.com/r/lenisha/vsts-agent-infrastructure/
We will use Terraform available in Azure CloudShell to setup the ACI container group and run the container based on this image. (It could be done from any command line with AZ CLI installed, and az login is performed.)
- Open CloudShell and clone the GitRepo containing Terraform template for ACI running custom agent
git clone https://github.com/lenisha/vsts-agent-infrastructure.git
- Run terraform init, plan, and apply to create the infrastructure with the following code:
cd vsts-agent-infrastructure/terraform terraform init terraform apply -var vsts-account=<vsts account> -var vsts-token=<pat token>
Upon completion verify that the agent is up and running.
Azure Container Instances would look like this:
VSTS Agent Pool reflects the new Agent:
The agent will now be “online,” as pictured below.
This configuration is a perquisite for a 2-part tutorial that demonstrates how to continuously build and deploy Azure infrastructure for applications running on Azure. You can start with Part 1 here.