To make the brine, in a large stockpot, bring 1 gallon of the water to a boil. Stir in the salt and sugar until completely dissolved. Turn off the heat and add the onions, carrot, celery, leek, thyme, bay leaves, peppercorns, coriander and fennel seeds, red pepper flakes, and star anise, if using. Stir in the remaining 1 gallon cold water. Let the brine cool completely, then refrigerate until cold.
Rinse the turkey inside and out with cold water. Carefully place the turkey in the brine. To keep the turkey submerged in the brine, place a weight such as a heavy plate or pot lid on top of the bird. Refrigerate for 72 hours.
Remove the turkey from the brine and pat dry (discard the brine). Place the turkey on a rack in a large roasting pan and rub all over with olive oil. Let sit for 1 hour to come to room temperature.
Preheat the oven to 425°F.
Roast until the turkey starts to brown, about 25 minutes. Turn down the oven to 350°F and roast about 10 minutes per pound, for a total of 2 to 2½ hours, until an instant-read thermometer inserted in the thickest part of the thigh reads 160°F. As the turkey roasts, baste frequently with the pan juices, with the rosemary brush, if using. If the bird begins to darken too much, cover loosely with foil.
Remove the turkey from the oven, transfer to a serving platter, and let rest for 20 minutes before carving.