The War with Mexico was fought on the pretext of relieving the Mexican people of their ruling junta. In fact the point was clear to many in Congress that the purpose was really "regime change" to remove the threat to the newly annexed Texas, and a land grab for the territory in the Southwest (New Mexico and California). Animating all this was the issue of whether any new states would be free or allow slaveholding. The issue came to a head on the point of allowing people migrating to the new territories to bring along their "property", that is, slaves.
The rush to grab land on flimsy pretext and create new states BEFORE settling the issue of slavery POLITICALLY, led directly to bitter sectional infighting and eventually the Civil War, which could be regarded as the price we paid for our bad foreign policy.
Grant himself, who served with distinction, called the Mexican war "unjust".