Nitrogen in fertilizer is extracted from the air (not from petroleum as stated). The hydrogen can be gotten from electrolysis of water, or from methane.
Natural gas is overwhelmingly used for the production of ammonia..." — Wikipedia
So, sure, we use energy to create fertilizer. Instead of mining it and shipping it, or going without. Again, if it wasn't the cheaper alternative we wouldn't be doing it.