fair-weather friend
US /ˈferˌweð.ər ˈfrend/
UK /ˈferˌweð.ər ˈfrend/

1.
a person who is only a friend when things are going well and abandons you when difficulties arise
:
•
I thought he was my friend, but he turned out to be a fair-weather friend when I lost my job.
•
Don't rely on him; he's just a fair-weather friend.