|
|
|
|
@ -97,6 +97,15 @@ func (s *stepSecurity) Run(_ context.Context, state multistep.StateBag) multiste
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *stepSecurity) Cleanup(state multistep.StateBag) {
|
|
|
|
|
secRuleName, ok := state.GetOk("security_rule_name")
|
|
|
|
|
if !ok {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
secListName, ok := state.GetOk("security_list")
|
|
|
|
|
if !ok {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
client := state.Get("client").(*compute.ComputeClient)
|
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
|
config := state.Get("config").(*Config)
|
|
|
|
|
@ -105,37 +114,38 @@ func (s *stepSecurity) Cleanup(state multistep.StateBag) {
|
|
|
|
|
|
|
|
|
|
namePrefix := fmt.Sprintf("/Compute-%s/%s/", config.IdentityDomain, config.Username)
|
|
|
|
|
// delete security rules that Packer generated
|
|
|
|
|
secRuleName := state.Get("security_rule_name").(string)
|
|
|
|
|
secRulesClient := client.SecRules()
|
|
|
|
|
ruleInput := compute.DeleteSecRuleInput{Name: namePrefix + secRuleName}
|
|
|
|
|
ruleInput := compute.DeleteSecRuleInput{Name: namePrefix + secRuleName.(string)}
|
|
|
|
|
err := secRulesClient.DeleteSecRule(&ruleInput)
|
|
|
|
|
if err != nil {
|
|
|
|
|
ui.Say(fmt.Sprintf("Error deleting the packer-generated security rule %s; "+
|
|
|
|
|
"please delete manually. (error: %s)", secRuleName, err.Error()))
|
|
|
|
|
"please delete manually. (error: %s)", secRuleName.(string), err.Error()))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// delete security list that Packer generated
|
|
|
|
|
secListName := state.Get("security_list").(string)
|
|
|
|
|
secListClient := client.SecurityLists()
|
|
|
|
|
input := compute.DeleteSecurityListInput{Name: namePrefix + secListName}
|
|
|
|
|
input := compute.DeleteSecurityListInput{Name: namePrefix + secListName.(string)}
|
|
|
|
|
err = secListClient.DeleteSecurityList(&input)
|
|
|
|
|
if err != nil {
|
|
|
|
|
ui.Say(fmt.Sprintf("Error deleting the packer-generated security list %s; "+
|
|
|
|
|
"please delete manually. (error : %s)", secListName, err.Error()))
|
|
|
|
|
"please delete manually. (error : %s)", secListName.(string), err.Error()))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Some extra cleanup if we used the winRM communicator
|
|
|
|
|
if config.Comm.Type == "winrm" {
|
|
|
|
|
// Delete the packer-generated application
|
|
|
|
|
application := state.Get("winrm_application").(string)
|
|
|
|
|
application, ok := state.GetOk("winrm_application")
|
|
|
|
|
if !ok {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
applicationClient := client.SecurityApplications()
|
|
|
|
|
deleteApplicationInput := compute.DeleteSecurityApplicationInput{
|
|
|
|
|
Name: namePrefix + application,
|
|
|
|
|
Name: namePrefix + application.(string),
|
|
|
|
|
}
|
|
|
|
|
err = applicationClient.DeleteSecurityApplication(&deleteApplicationInput)
|
|
|
|
|
if err != nil {
|
|
|
|
|
ui.Say(fmt.Sprintf("Error deleting the packer-generated winrm security application %s; "+
|
|
|
|
|
"please delete manually. (error : %s)", application, err.Error()))
|
|
|
|
|
"please delete manually. (error : %s)", application.(string), err.Error()))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|