IaC Cost Patterns

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

Antipattern: Old generation

Using newer resource generations gives similar performance for lower cost.

Context

Cloud providers occasionally update their offerings to support, for example, newer CPU generations. These newer generations are often more efficient, making them a more economical option compared to older generations.

Solution

Upgrade resources to newer generations to attain comparable or better performance for a lower price. The most commonly replaced resources include, but are not limited to, AWS's t2 general-purpose compute instances and gp2 storage volumes.

Example

Switch from gp2 to gp3 storage, providing comparable performance but lower cost:

@@ -1,7 +1,7 @@
 resource "aws_instance" "example" {
   # ...
   root_block_device {
-    volume_type = "gp2"
+    volume_type = "gp3"
     # ...
   }
 }

References

Occurrences

Terraform

AWS CloudFormation