Platform Engineering
Fix it Fix it Fix it: Automation is Scientific Magic Part 1
In the Beginning

Hello, and welcome to the first installment of Fix it Fix it Fix it. This series captures the day-to-day life of the Mentat DevOps engineering team as we enjoy the struggle and excitement of automating the world.
Most of the projects we take on at Mentat are extremely difficult enterprise hybrid-cloud problems. This one started with a client who had an Azure Automation project that was “almost complete” and needed help tying everything together into a repeatable deployment for a website stack.
It sounded like a quick automation win. The team already had code, and we had deep Azure experience. But once we dug in, it became clear that the “almost completed” code was nowhere near functional. Solr, Mongo, and IIS did not install automatically, the ARM templates only occasionally worked, and even successful deployments left most of the infrastructure misconfigured.
So we started over and built an automated pipeline with single-click deployment.
Solution Tech Stack
Earth-Shaping
To tackle the work quickly, we spun up a Jenkins server, integrated it with our internal GitLab, and immediately began recreating the ARM templates in Terraform.
If you have never used Terraform before, it is one of the most effective tools for deliberately shaping cloud infrastructure. In this project, Terraform let us rewrite the ARM templates into modular infrastructure-as-code that could reliably deploy the full Solr, Mongo, and IIS stack in minutes.
The implementation started with a simple root directory and a modules directory. The root site.tf file defined how to connect to Azure and referenced the modules to be executed. Each module then contained the provider-specific resource definitions and the variables required by that module.
Below is a snippet from the MongoDB module:
resource “azurerm_network_interface” “mongo_nics” {
count = “${var.mongo_config[“vm_count”]}”
name = “${format(“%s-%02d”, var.mongo_nics[“name”], count.index + 1)}”
location = “${var.location}”
resource_group_name = “${var.azurerm_resource_group[“name”]}”
ip_configuration {
name = “${format(“%s-%0d”, var.mongo_nics[“ip_configuration_name”], count.index + 1)}”
subnet_id = “${var.mongo_subnet_id}”
private_ip_address_allocation = “${var.mongo_nics[“private_ip_address_allocation”]}”
}
}
resource “azurerm_managed_disk” “mongo_vm_disks” {
resource_group_name = “${var.azurerm_resource_group[“name”]}”
location = “${var.location}”
name = “${var.mongo_vm_disks[“name”]}”
storage_account_type = “${var.mongo_vm_disks[“storage_account_type”]}”
disk_size_gb = “${var.mongo_vm_disks[“disk_size_gb”]}”
create_option = “${var.mongo_vm_disks[“create_option”]}”
}
resource “azurerm_virtual_machine” “mongo_vm” {
resource_group_name = “${var.azurerm_resource_group[“name”]}”
location = “${var.location}”
count = “${var.mongo_config[“vm_count”]}”
name = “${format(“%s-%02d”, var.mongo_vm[“name”], count.index + 1)}”
network_interface_ids = [“${element(azurerm_network_interface.mongo_nics.*.id, count.index)}”]
vm_size = “${var.mongo_vm[“vm_size”]}”
delete_os_disk_on_termination = true
delete_data_disks_on_termination = true
storage_image_reference {
publisher = “${var.mongo_vm[“storage_image_reference_publisher”]}”
offer = “${var.mongo_vm[“storage_image_reference_offer”]}”
sku = “${var.mongo_vm[“storage_image_reference_sku”]}”
version = “${var.mongo_vm[“storage_image_reference_version”]}”
}
storage_os_disk {
name = “${format(“%s-%0d”, var.mongo_vm[“storage_os_disk_name”], count.index + 1)}”
caching = “${var.mongo_vm[“storage_os_disk_caching”]}”
create_option = “${var.mongo_vm[“storage_os_disk_create_option”]}”
managed_disk_type = “${var.mongo_vm[“storage_os_disk_managed_disk_type”]}”
}
os_profile {
computer_name = “${format(“%s-%0d”, var.mongo_vm[“os_profile_computer_name”], count.index + 1)}”
admin_username = “${var.mongo_vm[“os_profile_admin_username”]}”
admin_password = “${var.mongo_vm[“os_profile_admin_password”]}”
}
tags {
environment = “Dev”
}
}How the Terraform Layout Worked
The naming conventions and directory layout were intentionally simple: the root directory held the top-level Terraform entry point, while the modules directory stored each reusable infrastructure component.
Once the basic structure was in place, the remaining work became mostly about reading the Azure provider documentation, defining resources carefully, and composing the right modules for the Solr, Mongo, and IIS stacks.
From there the core Terraform workflow stayed straightforward: Terraform Get to download and update referenced modules, Terraform Plan to generate an execution plan and catch syntax issues, and Terraform Apply to build the infrastructure and generate state.
One of the nicest advantages of this approach was reuse. After building the MongoDB module, we could copy the pattern into the other modules and only change the names and details specific to each stack.
Groovy Cloud Duct Tape
With the base infrastructure working, we committed the code to Git and let Jenkins automatically run a test build.
Jenkins became the duct tape that tied the environment together. We rapidly spun up a Jenkins master in Azure, integrated it with source control, and used pipelines to run Terraform-based builds and notify the team when jobs completed.
The result was a clean baseline deployment flow for Solr, MongoDB, Zookeeper, and IIS. The service-configuration side still remained, which set up the next chapter of the story: using PowerShell DSC and Chocolatey to install and configure the application layer on top of the infrastructure.
P.S.
This post was originally released in 2018, so the Terraform syntax is intentionally preserved in its older form.

Key takeaway
Ready to automate smarter?
When “almost complete” automation is unreliable, the fastest path is often to rebuild around deterministic infrastructure-as-code and a clean deployment pipeline.