IaC Cost Patterns

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

Antipattern: Expensive instance

Compute instances are often overprovisioned even when a cheaper instance would suffice.

Context

A recurring pattern in cloud deployments is that developers initially choose compute instances which are overprovisioned, because it is difficult to know the requirements upfront. This leads to situations where developers deploy, for example on AWS, '2xlarge' instances, when in fact 'large' or even 'medium' would suffice.

Solution

Critically evaluate required performance levels and special functionality (e.g. memory-optimized versus general-purpose instances), and scale down the provisioned instance types where appropriate.

Example

Downgrade to a cheaper general-purpose instance in the same family to save costs:

@@ -1,5 +1,5 @@
 resource "google_compute_instance" "example" {
   name         = "example"
-  machine_type = "n1-standard-1"
+  machine_type = "g1-small"
   # ...
 }

References

Occurrences

Terraform

AWS CloudFormation