I'm reminded of Lenin's "the ends justify the means" approach as another example of the problems that can arise from this line of reasoning.
An important issue is what the ends are.
Putin invading Ukraine for the purpose of conquest
is vastly different from USA warring with Japan to
stop its conquest in the Pacific.
As for the "ends", the tools of war are terrible things. What
matters is their usage resulting in an outcome that's better
than not using them. We can argue about which tools are
right or wrong, eg, frangible bullets vs ball ammo, nuclear
weapons vs firestorms, dirty bombs vs neutron bombs,
justifiable level of civilian deaths.
Terrible things will be done so as to win....or to not lose.
We can only strive to minimize the carnage toward that end.
The tools of war will also vary with the plight of the defender,
ie, if one's non-existence looms nigh, then more extreme
tools will be employed, with arguable morality. If one is
relatively powerless against a larger foe, then tools such
as terrorism will be employed...even though we call them
immoral, it's what happens in such circumstances.
Morality is highly relative.
The reality of war is that the ends do justify the means
to varying degrees, depending upon circumstances.
Putin's proffered reasons for invading Ukraine are
dishonest, so he needs no pretext based upon anything
USA did. He will do what he will do.
In our age, with the benefit of hindsight, I favor using
nuclear weapons solely as a threat, ie, the MAD strategy.
But during WW2, I see different circumstances for the
decision to use nuclear weapons.