If you got the shot for the primary purpose of avoiding pregnancy, that was wrong. If you got the shot for another medical purpose, with infertility or possible infertility as a side-effect, that is permissble. It does not matter if the side-effect is welcome or not. All that matters is that you decided in favor of the shot because it was needed for a purpose that was other than avoiding pregnancy.
For instance, if you had heavy bleeding and the doctor prescribed this to address that issue, it is permissible to choose what your doctor considers the best treatment for the problem, even if infertility is a possible side-effect.
This is different than choosing a treatment that would end a pregnancy already in progress. In that case, the life of both the child and the mother have to be favored over other treatments. When there is already a pregnancy, you can neither kill the mother to save the child nor kill the child in order to save the mother. One or the other might be put at some risk as an unintended side effect, but you can’t directly kill one for the sake of the other.