For automated deployment, you will find a different kind of tooling available for DevOps purposes, for example, Jenkins or Ansible, or Chef. A few of them are suited for infrastructure deployment and these are for example Azure Automation and Terraform, each come with up and downsides.
You can use Azure Automation Manager to automate workflows. Unfortunately, the Microsoft Azure Automation Manager is still working with an older version of PowerShell (5.1.15063). So not all commands and their variables are written differently and have fewer features compared to the new PowerShell Az module.
The problem for using deploying infrastructure as a code the Azure Automation Manager is quite limited. Had some issues with network creation, not recognized the PowerShell commands for newly created network profiles. No new deployment VM from scratch, only support of generalized disks import and creating VM from it. Not all PowerShell commands are recognized, so it is quite hard to get it working, despite the available CMDLETS view how to use the commands.
When we are looking at the features of Terraform tooling can be seen as a multi-platform automation tooling for deploying docker containers. Terraform can be started from the PowerShell command locally on your computer, which is a big plus for me, and all you need to do is creating the main.tf configuration file which all the commands and features of your Infrastructure as a Code environment. The downside of using Terraform, you need to learn the Terraform language, but the use of the commands, syntax, and features are well documented and quite clear how to use them.
The possibilities are almost endless by using Terraform infrastructure. Again thanks to the Terraform user community you can use different kinds of published modules for deploying your IAAC environments complete with firewall and domain controller infrastructure. But it is more fun programming yourself and you’ll learn more about how to use the different features, so we start with this example the creation of a docker environment into an existing resource group by programming a configuration module file, called main.tf.
For connecting to the Microsoft Azure environment the following section needed to be added:
# Configure the Microsoft Azure Provider terraform { required_providers { azurerm = { source = "hashicorp/azurerm" version = "~>2.0" } } } provider "azurerm" { features {} }
For creating a new ResourceGroup the script section below is added, but when the resource group already exists, you need to use the “terraform import function with what you want to import, in this case, the terraform resource to the existing Microsoft Azure Resource group location.
# Create a resource group if it doesn't exist resource "azurerm_resource_group" "resourcegroup" { name = "<Name>" location = "West Europe" tags = { environment = "Demo" } }
And now you can add for example the creation of a network environment by adding the following sections to your script:
# Create virtual network resource "azurerm_virtual_network" "network" { name = "myVnet" address_space = ["10.0.0.0/16"] location = "West Europe" resource_group_name = azurerm_resource_group.network.name tags = { environment = "Demo" } } # Create subnet resource "azurerm_subnet" "subnet" { name = "mySubnet" resource_group_name = azurerm_resource_group.resourcegroup.name virtual_network_name = azurerm_virtual_network.network.name address_prefixes = ["10.0.1.0/24"] }
When executing this script in Terraform the code is executed in Microsoft Azure and the requested resources are created. The script can be extended with multiple VMs using domain infrastructure environment configurations. At the end you only need to add and configure the Desired State Configuration of the VM, adding application and other add-on features can be done by using Azure VM custom script extensions. How that works you can find in my earlier blogposts series “PowerShell your DevOps”. In the next blog post, I will deep dive more into the possibilities of setting up and deploying infrastructure as a Code with Terraform.
References and more background information about Terraform:
Get Started – Configure Terraform in Azure Cloud Shell with Bash | Microsoft Docs
Use infrastructure automation tools – Azure Virtual Machines | Microsoft Docs