Much as I agree that Russia's invasion was bad (even if it turns out to be technically legal under UN Article 51), this statement of yours is just completely at odds with history.
NATO attacked Yugoslavia, Libya, and Syria to name just 3 countries that did NOT attack NATO countries. Yes, all three countries were/are lead by brutal dictators. They just happened to be brutal dictators that were (or stopped being) friendly with the US. This is exactly the situation that Putin, another brutal dictator, finds himself.
I may not like Putin, but my opinion here doesn't matter. Putin can look at what has happened with other NATO countries, and NATO aggression, and his gas-dependent country, and rationally conclude that losing Ukraine to NATO would eventually lead to war with NATO, and that Russia would be severely weakened by Ukraine in NATO prior to that war.