File tree 4 files changed +33
-9
lines changed
4 files changed +33
-9
lines changed Original file line number Diff line number Diff line change @@ -150,8 +150,8 @@ func refreshResources(providers []*provider.Provider) {
150
150
// errs = provider.ResumeResources(resumableResources)
151
151
// fmt.Println("Errors Resuming Resources: ", errs)
152
152
153
- // destroyableResources := provider.GetDestroyableResources(allResources)
154
- // fmt.Println("Destroyable Resources: ", destroyableResources)
153
+ destroyableResources := provider .GetDestroyableResources (allResources )
154
+ fmt .Println ("Destroyable Resources: " , destroyableResources )
155
155
// errs = provider.DestroyResources(destroyableResources)
156
156
// fmt.Println("Errors Destroying Resources: ", errs)
157
157
}
Original file line number Diff line number Diff line change @@ -62,22 +62,18 @@ rules:
62
62
env : test
63
63
ci : true
64
64
condition :
65
- terminationPolicy :
66
- - older than 24hrs
65
+ terminationPolicy : older than 24hrs
67
66
- name : Nuke all project A instances after Demo october 9th (staging)
68
67
tags :
69
68
env : staging
70
69
project : A
71
70
condition :
72
71
terminationDate : october 9
73
- action : terminate
74
72
- name : Delete all unused instances older than 48hrs (staging)
75
73
tags :
76
74
env : staging
77
75
condition :
78
- terminationPolicy :
79
- - unused
80
- action : terminate
76
+ terminationPolicy : unused
81
77
82
78
83
79
timezone : Africa/Lagos
Original file line number Diff line number Diff line change @@ -75,6 +75,8 @@ func ParseRule(rule Rule) Ruler {
75
75
activeRule = & ActiveDurationRule {Rule : & rule }
76
76
} else if rule .Condition .TerminationDate != "" {
77
77
activeRule = & TerminationDateRule {Rule : & rule }
78
+ } else if rule .Condition .TerminationPolicy != "" {
79
+ activeRule = & TerminationPolicyRule {Rule : & rule }
78
80
} else {
79
81
log .Fatalf ("No Conditions specified for rule: `%s`" , rule .Name )
80
82
}
Original file line number Diff line number Diff line change 8
8
"github.com/mensaah/reka/resource"
9
9
)
10
10
11
- // TerminationDateRule defines rule that sets when a resource should be terminated
11
+ // TerminationDateRule defines rule that sets when a resource should be terminated based on termination-date rule
12
+ // set in config file. This rule checks if the set termination-date is past and activates destroy on the instance
12
13
type TerminationDateRule struct {
13
14
* Rule
14
15
Date time.Time
@@ -72,3 +73,28 @@ func (r ActiveDurationRule) CheckResource(res *resource.Resource) Action {
72
73
}
73
74
return DoNothing
74
75
}
76
+
77
+ // TerminationPolicyRule defines rule that sets when a resource should be terminated.
78
+ type TerminationPolicyRule struct {
79
+ * Rule
80
+ Policy string
81
+ }
82
+
83
+ func (r * TerminationPolicyRule ) validate () error {
84
+ validPolicies := []string {"unused" }
85
+ for _ , p := range validPolicies {
86
+ if p == r .Condition .TerminationPolicy {
87
+ return nil
88
+ }
89
+ }
90
+ r .Policy = r .Condition .TerminationPolicy
91
+ return fmt .Errorf ("Error parsing condition.terminationPolicy: Invalid Policy %s" , r .Policy )
92
+ }
93
+
94
+ // CheckResource Returns a list of resources whose termination Date is exceeed
95
+ func (r TerminationPolicyRule ) CheckResource (res * resource.Resource ) Action {
96
+ if res .IsUnused () {
97
+ return Destroy
98
+ }
99
+ return DoNothing
100
+ }
You can’t perform that action at this time.
0 commit comments