// Release releases all address for the given region/client // // TODO(rjeczalik): add logger func (a *Addresses) Release(client *amazon.Client) { if len(a.m) == 0 { return } addresses := a.m[client] fmt.Printf("Releasing %d addresses for region %s\n", len(addresses), client.Region) for _, addr := range addresses { ip := aws.StringValue(addr.PublicIp) assocID := aws.StringValue(addr.AssociationId) if assocID != "" { // EIP is in-use, disassociate it first. err := client.DisassociateAddress(assocID) if err != nil { // Even when it fails, will try to release the EIP. fmt.Printf("[%s] disassociate %s EIP error: %s\n", client.Region, ip, err) } } allocID := aws.StringValue(addr.AllocationId) err := client.ReleaseAddress(allocID) if err != nil { fmt.Printf("[%s] release %s EIP error: %s\n", client.Region, ip, err) } } fmt.Printf("Releasing is done for region %s\n", client.Region) }