Terpenoids are generally considered defence compounds. Some volatile terpenoids are involved in signalling, attaching "bodyguards" that attack herbivores.
I cover this in a chapter of our textbook, Plant Physiological Ecology at a fairly global level.
In addition to what has been stated by Hans Lambers secondary metabolites impart resistance to biotic and abiotic stresses, attract pollinators, repel pests (defensive role), can be converted back to primary metabolites in times of need and act as energy sources. There is an excellent review on the subject:
Croteau, R. (1987) Biosynthesis and catabolism of monoterpenoids. Chem. Rev. 87: 929-954.