IaC Cost Patterns

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

Antipattern: Overprovisioned resources

Resources like RAM, storage and CPU utilization are often overprovisioned even when lower values are acceptable.

Context

In a similar way to overprovisioned instances, it is difficult to estimate required limits for resources such as root storage upfront, leading developers to overprovision them, in turn raising costs.

Solution

Evaluate the resource requirements and lower the relevant values.

Example

Shrink the root storage size of an instance to reduce storage costs:

@@ -2,6 +2,6 @@ resource "aws_instance" "example" {
   # ...
   
   root_block_device {
-    volume_size = 20 # GB
+    volume_size = 15 # GB
   }
 }

References

Occurrences

Terraform

AWS CloudFormation