There are a couple of challenges to this sort of thing.
1. Identify enzymes that can produce the desired product.
2. Get the genes for these enzymes into your organism.
3. Will the product be readily metabolized by or toxic to your organism? If so, additional work will be needed. (Marijuana is an interesting example in that it produces much of its THC in a location that isolates it from the rest of the plant's metabolism (on the trichome hairs on the buds.))
In many cases, nature has already done the work for us; we have organisms that produce all manner of interesting materials, such as mescaline, cocaine, morphine, DMT, safrole, ephedrine, etc. (I heard that a plant that produced traces of meth had been found, but can't find a reference....)
I would bet vast sums of money that this represents the future of the drug trade, although it's probably a few decades off. When the day comes when a tiny sample of desiccated cells in a mailed letter can be grown in multi-kilo vats of cocaine- or morphine-producing yeast with little more than sugar and water, the drug war will become even less effective. (With fungi or bacteria, you wouldn't even need the power-hungry lighting systems that often trip up large-scale pot growers.)
This is a very doable project. With advances in biotech, basic forms could probably be built on a modest budget (perhaps as little as a few thousand dollars if you already had access to lab space/equipment.)