Last week was a trying one for Canadian Prime Minister Justin Trudeau. You may think that I am referring to the imposition of U.S. tariffs on imports of Canadian steel. But Trudeau actually faced a harder issue than the one about how to respond to President Donald Trump’s declaration that trade with Canada posed a threat to U.S. security.

That was his decision to let the Canadian government purchase the Trans Mountain oil pipeline from Kinder Morgan (KMI.N) for $4.5 billion, and to finance its multibillion-dollar expansion. While the tariffs and pipeline are seemingly unrelated, the imposition of the first should ease criticism of Trudeau’s pipeline decision, given that the recent U.S. move highlights the growing unreliability of Canada’s ally to the south. 

For decades, Canada was content to rely on the U.S. as its only market for its most important exports: not steel, but oil and gas. Virtually all of Canada’s oil and gas exports flow to the U.S. and always have. Energy exports to the U.S. make up slightly more than a fifth of all Canadian exports and a little more than 5 per cent of Canada’s gross domestic product. 

In recent years, however, many Canadians have wanted their country to develop the ability to export oil and gas to other markets. Some of the impetus for this sentiment was political, beginning well before Trump arrived in the White House. In 2011, Prime Minister Stephen Harper ordered his cabinet to begin the exploration of alternative export routes after two tense exchanges with President Barack Obama concerning the Keystone Pipeline.

But much of the drive to send Canadian energy elsewhere is rooted in market realities. In the last 10 years, the advent of fracking and the subsequent production of shale gas in the U.S. has reduced American demand for Canadian natural gas, driving down imports by more than a fifth. The U.S. actually imports more oil from Canada than ever before, but America’s burgeoning oil production may cause Canadians to wonder if this will always be the case.

The imperative for Canada to find non-U.S. energy markets is easy to understand. But the ability to act on this vision has proven elusive. Large pipelines need to be built from Alberta, the fountain of most Canadian oil and gas, to one of the two distant coasts, with the western one making the most sense given both geography and the fact that Asia is the center of energy demand growth.

North American companies have sought to build pipelines that would carry Canadian energy to the ports, but environmentalists in British Columbia and elsewhere have resisted and in most cases thwarted these efforts.

The plan to expand the Trans Mountain pipeline from Alberta to British Columbia began to look like it would be no exception. Threats began to fly between the two provinces, and in February, Alberta briefly banned the “import” of wine made in British Colombia. Since March, Alberta’s premier has been threatening to cut off the flow of oil to its western neighbor.

Finally, after years of effort, Kinder Morgan declared on April 8 that it would suspend its expansion project if the legal and regulatory challenges were not settled in its favor by May 31.

Canada was in a national emergency. Leading figures in the east, including Trudeau, stressed that completing the pipeline expansion was in the national interest. Polls showed that most Canadians agreed. Yet Trudeau’s government had not done enough to assure the pipeline company that this infrastructure could be built, despite the fact that it had the power to approve and regulate interprovincial pipelines and railways.

Faced with unpalatable options, Trudeau took the correct course in announcing on May 29 that it had purchased the existing pipeline and would ensure that the expansion project would be completed. He has been criticized from all sides for this action. Some detractors point out that it will entail political costs for his Liberal Party, while not necessarily enabling him to achieve all his climate and energy objectives. Others lament the negative signal sent to investors by the need for federal intervention.

There is no debate that it would be better for Canada if the Trans Mountain pipeline controversy had never gotten to this stage. Trudeau’s move does not clear away all the legal and regulatory barriers, but it will be harder for activists to stand in the way of a federal project. And rarely do policymakers get to choose between a good option and a bad one; instead, they get to select between flawed alternatives, hoping to pick the least bad.

Had Trudeau chosen to let Kinder Morgan cancel the project, investors would have looked at Canada in a less favorable light. They would no longer see Canada as a country of minimal political risk, but would have instead focused on uncertainty around the rule of law. For now, the big questions about whether laws will be enforced and federal prerogatives protected have been put to rest. 

A cancellation of the Trans Mountain pipeline expansion would have been a significant setback in Canada’s pursuit of new international energy markets, something very much in the Canadian interest. Trump’s imposition of steel and aluminum tariffs on Canada seemed to punctuate this message sharply and may have even given Trudeau’s opponents a moment of pause. At this point, sadly, any step that helps reduce Canadian dependence on U.S. markets should strike Canadians as a smart one.