2017-03-03 03:56:17 -05:00
|
|
|
package ecs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-04-25 22:37:49 -04:00
|
|
|
"strconv"
|
2017-06-01 20:14:51 -04:00
|
|
|
|
2020-11-17 19:31:03 -05:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
2020-11-19 14:54:31 -05:00
|
|
|
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
2017-03-03 03:56:17 -05:00
|
|
|
)
|
|
|
|
|
2019-04-25 22:37:49 -04:00
|
|
|
func cleanUpMessage(state multistep.StateBag, module string) {
|
2017-03-03 03:56:17 -05:00
|
|
|
_, cancelled := state.GetOk(multistep.StateCancelled)
|
|
|
|
_, halted := state.GetOk(multistep.StateHalted)
|
|
|
|
|
2020-11-19 14:54:31 -05:00
|
|
|
ui := state.Get("ui").(packersdk.Ui)
|
2017-03-03 03:56:17 -05:00
|
|
|
|
|
|
|
if cancelled || halted {
|
2017-06-01 22:33:12 -04:00
|
|
|
ui.Say(fmt.Sprintf("Deleting %s because of cancellation or error...", module))
|
2017-03-03 03:56:17 -05:00
|
|
|
} else {
|
2017-06-01 22:33:12 -04:00
|
|
|
ui.Say(fmt.Sprintf("Cleaning up '%s'", module))
|
2017-03-03 03:56:17 -05:00
|
|
|
}
|
|
|
|
}
|
2018-11-19 02:25:12 -05:00
|
|
|
|
|
|
|
func halt(state multistep.StateBag, err error, prefix string) multistep.StepAction {
|
2020-11-19 14:54:31 -05:00
|
|
|
ui := state.Get("ui").(packersdk.Ui)
|
2018-11-19 02:25:12 -05:00
|
|
|
|
2018-11-28 08:34:21 -05:00
|
|
|
if prefix != "" {
|
|
|
|
err = fmt.Errorf("%s: %s", prefix, err)
|
|
|
|
}
|
|
|
|
|
2018-11-19 02:25:12 -05:00
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
2019-04-25 22:37:49 -04:00
|
|
|
|
|
|
|
func convertNumber(value int) string {
|
|
|
|
if value <= 0 {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
return strconv.Itoa(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ContainsInArray(arr []string, value string) bool {
|
|
|
|
for _, item := range arr {
|
|
|
|
if item == value {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|