fix ordering of deleting security rules and lists

This commit is contained in:
Megan Marsh 2018-01-25 09:17:30 -08:00 committed by Matthew Hooker
parent 76ea73c5b2
commit 1fffbacdd3
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1
2 changed files with 13 additions and 11 deletions

View File

@ -20,7 +20,6 @@ func (s *stepCreateInstance) Run(state multistep.StateBag) multistep.StepAction
keyName := state.Get("key_name").(string)
ipAddName := fmt.Sprintf("ipres_%s", config.ImageName)
// secListName := "Megan_packer_test" // hack to get working; fix b4 release
secListName := state.Get("security_list").(string)
netInfo := compute.NetworkingInfo{

View File

@ -71,23 +71,26 @@ func (s *stepSecurity) Cleanup(state multistep.StateBag) {
client := state.Get("client").(*compute.ComputeClient)
ui := state.Get("ui").(packer.Ui)
ui.Say("Deleting the packer-generated security rules and lists...")
// delete security list that Packer generated
secListName := state.Get("security_list").(string)
secListClient := client.SecurityLists()
input := compute.DeleteSecurityListInput{Name: secListName}
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()))
}
// delete security rules that Packer generated
secRuleName := state.Get("security_rule_name").(string)
secRulesClient := client.SecRules()
ruleInput := compute.DeleteSecRuleInput{Name: secRuleName}
err = secRulesClient.DeleteSecRule(&ruleInput)
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()))
}
// delete security list that Packer generated
secListName := state.Get("security_list").(string)
secListClient := client.SecurityLists()
input := compute.DeleteSecurityListInput{Name: secListName}
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()))
}
return
}