IaC Cost Patterns

A collection of patterns and antipatterns for managing cost in IaC files.

Antipattern: Expensive storage type

More expensive storage types are often used even when cheaper storage types would be sufficient.

Context

Developers are able to choose between different storage types (HDD vs SSD, durability guarantees) for e.g. instances' root disks. However, not all use cases require highly durable SSD storage, making cheaper storage types a viable way to save cost.

Solution

Evaluate performance and durability guarantees for storage and switch to a less expensive type where relevant.

Example

Switch an OS disk from Premium LRS storage to Standard LRS:

@@ -1,6 +1,6 @@
 resource "azurerm_linux_virtual_machine" "example" {
   # ...
   os_disk {
-    storage_account_type = "Premium_LRS"
+    storage_account_type = "Standard_LRS"
   }
 }

References

Occurrences

Terraform

AWS CloudFormation