IaC Cost Patterns

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

Pattern: Preventative Template

Templates with predefined configurations that enforce cost-optimizing methods can proactively manage and reduce future expenses.

Context

Retroactively implementing cost-saving changes can be inefficient and expensive, especially in the context of large systems.

Solution

Preventative templates can be designed to prioritize cost-optimizations and lead to a proactive enforcement of good practices further on.

Example

Adds a full file with a template for cost optimization that is not yet implemented within the project:

@@ -0,0 +1,111 @@ resource "template" "example" {
+  AWSTemplateFormatVersion: 2010-09-09
+  Description: Template for reducing costs on PN
+
+  Parameters:  
+    StopEc2FuctionTagName:
+      Type: String
+      Default: 'tostop'
+      Description: Name of EC2 Tag that will be stopped
+
+    StopEc2FuctionTagValue:
+      Type: String
+      Default: 'true'
+      Description: Value of EC2 Tag that will be stopped
+
+    StopEc2FuctionTagNameCronExpression:
+      Type: String
+      Default: 'cron(0 22 * * ? *)'
+      Description: Cron expression when ec2 stop
   # ...
}

References

Occurrences

AWS CloudFormation