If the country in question is attacking first. Essentially, that means a war on the turf of my own country, or on the turf of one of my nation's allies.
9/11 doesn't count. We were attacked by a group of people living in a country, not a country itself.
The you are never attacked by a country, even when a government declares war, the people that have nothing to do with politics and just want to live their life have nothing to do with it, yet they are the ones to end up dead and with missing limbs.