in lib/ec2macosinit/module.go [139:187]
func (m *Module) ShouldRun(instanceID string, history []History) (shouldRun bool) {
// RunPerBoot runs every time
if m.RunPerBoot {
return true
}
// The rest will use the history key
key := m.generateHistoryKey()
// RunPerInstance only runs if the module's key doesn't exist in the current instance history and has
// not run successfully.
if m.RunPerInstance {
// Check each instance in the instance history
for _, instance := range history {
if instanceID == instance.InstanceID {
// If the current instance matches an ID in the history, check every module history for that instance
for _, moduleHistory := range instance.ModuleHistories {
if key == moduleHistory.Key && moduleHistory.Success {
// If there is a matching key and it completed successfully, it doesn't need to be run
return false
}
}
// If there is an instance that matches and no keys match, run the module
return true
}
}
// If no instances match the instance history, run the module
return true
}
// RunOnce only runs if the module's key doesn't exist in any instance history
if m.RunOnce {
for _, instance := range history {
// Check every module history for that instance
for _, moduleHistory := range instance.ModuleHistories {
if key == moduleHistory.Key && moduleHistory.Success {
// If there is a matching key and it completed successfully, it doesn't need to be run
return false
}
}
}
// If no instances match the instance history, run the module
return true
}
// Default here is false, though this position should never be reached. Preference is to not run actions which
// may be potentially mutating but are misconfigured.
return false
}