You will have to improvise, to prevent de-railings.
When that fails, you may have to sit down and have a frank discussion with your party.
There are a lot of things that can be done to both allow for creative play and help keep a module on track. The longer you DM and the more practice you get the easier it will naturally become. So take a deep breath and dive in.
The first technique is to try and localize the impact of creative play. Your players are trying to make friends with the goblins so that they can gain some continuing tactical advantage. Localize the goblins, or in other worse, limit the scope of the goblins they do impact.
For example, you allow your party to make friends with some goblins. These goblins are part of a smaller tribe, and as soon as their defection becomes known, other goblin tribes are warned against defection and the goblins they did make friends with are now hunted. This could explain a hostility increase and refusal of future goblins to even speak with the party in encounters down the road as the pressure from other tribes / evil overlords make it very apparent that tribes seen talking to pink-skins will be dealt with harshly.
This could allow the party to gain a tactical or limited information advantage on a single encounter (like the known whereabouts of a lair, or the name of a bad guy) and then that information source is cut off. The localization also means that once the party leaves the immediate area of that small tribe, they would have to backtrack for their information source. Clans and tribes. D&D is not an industrialized homogeneous society. The feudal system is very modular and broken down into smaller squabbling factions held together by systematically larger and larger military powers.
But that's only one example of how to solve a specific problem. In my head I've divided adventure sourcebooks into two categories: Campaign sourcebooks and Module Packs. It is very easy to de-rail a Campaign sourcebook-style adventure, because of the open-ended nature of player choice of where to go and what do to. In these types of adventures, it's easy to go off-script. But there is a wealth of information about what else is going on in the world to help you recover or make a secondary plan.
The best course of action is to, rather than let your players run amok, allow the game to progress organically. Or, in other words: Let things play out as they would, rather than what your players want or how you think the adventure should go. You have time between adventures to play chess with the adventures with the other factions (and their responses) to things happening in the game. Danger, and the threat of danger, can do a lot to keep a player group tied down geographically.
If the Big Bad Evil guys hears about a new party of adventurers causing issues, what is to keep him from sending groups to counter and attack the support system of that party - to help wear them down? Or send a raid against the players' home-base town if they wander too far out of the area? Now the party will be more likely to stick closer to the designated area to protect the town. Or you can tie in the idea they need to do a favor for NPC X to help the villagers. This NPC just so happens to be the key NPC on the next module adventure, so it should work out.
But if the players don't buy your hooks or subtle nudges, you have only two choices: (a) Let them play out (Poor village gets nuked, and the monsters sent out 4 parties to raid the other 4 tombs simultaneously), or (b) stop the game and say honestly "Guys, were going to far off base here and I don't know how to handle it." I've had many DMs (myself included) do this, and the lengthy open discussion about where we want the game to go and kind of what needs to happen has done a lot to improve the quality of time at the table.
In situations like these, communication about the game the players want to play and the game the DM has prepared can go a long way to getting everyone on the same page. Sometimes letting the players in on a future basic plot summary can do a LOT to help keep players interested and playing along. Usually this is handled with foreshadowing, but that's not a skill every DM is good at. A little out-of-game knowledge can go a long way in this case.
The other thing that can come of this discussion is your campaign genuinely starts to move in a new direction. You just created a writers' circle for your campaign story. 5-6 heads are better than one, and now all the pressure you feel to solve this problem is being worked on by other people who care about the storyline.
Another thing that you can do is just say, "Hey, doing this will break my game at the moment and I don't know how to handle this. What can we do to marginalize this in a way that's acceptable, and then we can move forward with what I have prepared?" This is another common discussion I've had with other DMs. Good players should work with you on it. They care about the story too.