6.2. Infrastructure as Code
Infrastructure as Code (IaC) means configuring cloud services and infrastructure using code, rather than manually pointing and clicking in a web console.
The configuration lives in version-controlled code, right alongside the application or model code it supports.
This makes your infrastructure repeatable, auditable, and automated.
Why use IaC?
- Consistency – ensure every environment (dev, test, prod) is set up identically.
- Automation – spin up or tear down infrastructure with a single command.
- Speed – new environments for models, APIs, or experiments can be created in minutes.
- Versioning – infrastructure changes are tracked in Git, just like application code.
- Collaboration – analysts and engineers can share the same definitions for how systems should run.
Example in Pricing
A pricing team wants to deploy a new LightGBM model into production:
- With IaC, the cloud resources (compute instance, container registry, storage, networking) are defined in code.
- The same code can create a test environment for validation, and later a production environment for live deployment.
- If more compute power is needed for a large impact analysis, the configuration file can be updated and reapplied — no manual reconfiguration required.
Terraform
Terraform is one of the most popular IaC tools. It uses configuration files (.tf
) to define infrastructure in a cloud-agnostic way.
You declare what you want (e.g. a container, function, or database), and Terraform figures out how to build it.
Example Terraform File
```hcl
Define the provider (Azure in this case)
provider "azurerm" { features {} }
Resource group for pricing models
resource "azurerm_resource_group" "pricing" { name = "pricing-rg" location = "UK South" }
Container instance to run our model API
resource "azurerm_container_group" "pricing_model" { name = "pricing-model-api" location = azurerm_resource_group.pricing.location resource_group_name = azurerm_resource_group.pricing.name os_type = "Linux"
container { name = "model" image = "myregistry.azurecr.io/pricing-model:latest" cpu = "2" memory = "4"
ports {
port = 8080
protocol = "TCP"
}
}
ip_address { type = "Public" ports { port = 8080 protocol = "TCP" } } }