In you really want to be prepared for your next race you must consider the details of the race course. Although this may seem self-evident, athletes will often stick to their usual training routes out of habit and convenience. They may then find themselves woefully unprepared on race day. I have listened to many an athlete remark how challenging a particular course was post race. This should simply not be the case if even adequately prepped. The problem was in the preparation, not the course.
Hilly races requires intervals of strength and power, a flat course requires sustained strength endurance, and a rolling course will be a combination of the two. As you approach your goal race it is important to train as you will race as closely as possible. If there is one particular climb that everyone laments, race day is not the first time you should be facing the challenge. There are times in the season, such as base training, when course specificity is not as important. But the athlete that trains as closely as possible for the pending course will have a distinct leg up on the competition.
I advise my athletes to have a tool box of training courses. This means a flat course for sustained strength endurance work or tight zone work outs, a rolling course for repeatability, a long hill for sustained repeats, a track for speed work, an open water swim course, as well as a treadmill and stationary trainer. The closer you get to a peak race the more important is becomes to match the training course to your race course. We use these various training courses throughout the year depending on the work out, and if possible do some training on the actual race course itself.
I work with athletes that live in many areas of the country. Some have to drive miles to find a small hill and some have to do the same to find a flat section. This requires a level of adaptability and may mean spending time on a treadmill or trainer in order to be able to dial in training load. Another way we address these limitations is to schedule course specific work on the week ends when travel time is less of an issue. This is usually the case for open water swims, especially ocean or rive swims. Many of the virtual training apps allow you to "race" a course on your trainer, but this is not a substitute for road miles, more of a supplementation. The trainer does not work against gravity, just resistance.
Make sure you do some recon of your race course. This information has become much more easily/readily available with the advent of GPS technology. Many races now have elevation maps or GPS files posted on their websites which are very useful. And it is always good to get feedback from other athletes, but beware of subjectivity. Remember one person's mountain is another person's hill. Riding the course is always a good idea. If you have an uploadable GPS computer you can record the grade, elevation change, and length of the course. Get some perspective on what a 7 percent vs. a 10 percent grade feels like, and what gearing you use to climb it on the bike. There are simple devices that mount on your handlebar to estimate grade as well. Knowing when to sit up and when to stay in the drops or aero position throughout a course can create a huge dividends in speed.
If you find your race course has one long climb of 5 miles @ 8-12% grade then it is time to start looking for a similar place to train. You can break the course of into segments and train the harder sections individually. For example you may practice climbing a particular hill on your trainer with an elevated front wheel with the approximate length (time), resistance, and cadence you will need on race day. Athletes that train hilly courses predominantly may right off flat courses as "easier." They are not easier, just different. Flat races require more strength endurance as you do not get to coast the descents. Hills are like intervals whereas flats are like tempo workouts.
The first rule of training is specificity and the last thing you want to be is surprised on race day. Simply training the distance will leave you under trained and unpleasantly surprised on race day.