@@ -14,6 +14,7 @@ import (
14
14
"github.com/spf13/cobra"
15
15
"github.com/zclconf/go-cty/cty"
16
16
"regexp"
17
+ "strconv"
17
18
"strings"
18
19
"time"
19
20
)
@@ -23,6 +24,7 @@ var terraformCmd = &cobra.Command{
23
24
Short : "Create pull request for right sizing opportunities on your terraform git" ,
24
25
Long : "Create pull request for right sizing opportunities on your terraform git" ,
25
26
RunE : func (cmd * cobra.Command , args []string ) error {
27
+ ignoreYoungerThan := utils .ReadIntFlag (cmd , "ignore-younger-than" )
26
28
contentBytes , err := github .GetFile (
27
29
utils .ReadStringFlag (cmd , "github-owner" ),
28
30
utils .ReadStringFlag (cmd , "github-repo" ),
@@ -100,13 +102,22 @@ var terraformCmd = &cobra.Command{
100
102
rightSizingDescription := map [string ]string {}
101
103
for _ , item := range jsonObj .Items {
102
104
var recommendedInstanceSize string
105
+ maxRuntimeHours := int64 (1 ) // since default for ignoreYoungerThan is 1
103
106
for _ , device := range item .Devices {
104
107
for _ , property := range device .Properties {
108
+ if property .Key == "RuntimeHours" {
109
+ i , _ := strconv .ParseInt (property .Current , 10 , 64 )
110
+ maxRuntimeHours = max (maxRuntimeHours , i )
111
+ }
105
112
if property .Key == "Instance Size" && property .Current != property .Recommended {
106
113
recommendedInstanceSize = property .Recommended
107
114
}
108
115
}
109
116
}
117
+
118
+ if maxRuntimeHours < ignoreYoungerThan {
119
+ continue
120
+ }
110
121
if recommendedInstanceSize == "" {
111
122
continue
112
123
}
@@ -176,6 +187,10 @@ var terraformCmd = &cobra.Command{
176
187
description += fmt .Sprintf ("Changing instance class of %s to %s\n " , id , recommendation [id ])
177
188
description += rightSizingDescription [id ] + "\n \n "
178
189
}
190
+
191
+ if countRightSized == 0 {
192
+ return nil
193
+ }
179
194
return github .ApplyChanges (
180
195
utils .ReadStringFlag (cmd , "github-owner" ),
181
196
utils .ReadStringFlag (cmd , "github-repo" ),
0 commit comments