it is nearly always done in order to influence others (i.e. attempt to get enemy forces out of an area, weaken a strategic position, etc.)
as I already pointed out, there is no logical warrant for giving a magical exemption to governments and their agents (like militaries).
For painfully obvious reasons, official LEGAL definitions of terrorism are and continue to be tailored so as to avoid self-incrimination (those acting on behalf of governments AVOID setting up laws which would lead to identifying the state as having committed a criminal offense).
Once you remove the magical self-granted exemption from typical legal definitions, it becomes consistent and reasonable.
The bombings of Hiroshima and Nagasaki, for example, are archetypal cases of terrorism: they are massive incidences of planned violence carried out for the sake of attempting to influence the policy and conduct of others in a clear conflict (i.e. get the Japanese military/government to surrender).