But one tech leader has been clear about his support for the Pentagon, saying, “If big tech companies are going to turn their back on the U.S. Department of Defense, this country is going to be in trouble.” That was Jeff Bezos, chief executive of Amazon, in an interview with Wired on Oct. 15. Amazon is the likely winner of that contract — a state of affairs that prompted two members of Congress to call for an investigation into the bid process this week. Meanwhile, a site in Northern Virginia, down the road from the Pentagon, has emerged as a front-runner for Amazon’s second headquarters.

It may not be a popular position, but Mr. Bezos’s comments reveal an important truth: The Pentagon has been part of the Silicon Valley story all along. Defense contracts during and after World War II turned Silicon Valley from a somnolent landscape of fruit orchards into a hub of electronics production and innovations ranging from mainframes to microprocessors to the internet.

The American tech economy rests on the foundations of the military-industrial complex. Yet Silicon Valley’s culture is deeply influenced by skepticism about this same military establishment.

Unlike the atomic cities, Los Alamos, N.M., and Hanford, Wash., or the aerospace capitals, Los Angeles and Seattle, the Valley built small: microwaves and radar for high-frequency communication; transistors and integrated circuits. The nature of this work distanced the region’s technologists from the more ominous elements of America’s great scientific push. Silicon Valley built elegant miniaturized machines that could power missiles and rockets, but that also held endless possibilities for peaceful use, in watches, calculators, appliances and computers, large and small.

The result is an enduring technological optimism. Early Silicon Valley didn’t have a J. Robert Oppenheimer publicly despairing over his murderous creation. Instead, it had an ebullient regional booster, Fred Terman, an engineer and university administrator who used the bounty of military money to turn Stanford from a middling school with a good football team into an engineering powerhouse.

Big defense certainly made its mark. The region’s biggest employer from the 1950s through the end of the Cold War was Lockheed. Local start-ups of the time also benefited, and they attracted people with engineering backgrounds, not necessarily military ones. Take, for example, David Packard, the co-founder of Hewlett-Packard. An outspoken critic of government overreach, Packard believed that tech businesses should aspire to higher things. “I think many people assume, wrongly, that a company exists simply to make money,” he once told HP executives. “While this is an important result of a company’s existence, we have to go deeper to find the real reasons for our being.”

The next generation of Silicon Valley technologists took these sentiments further. They grew up dreaming of space and winning science fairs supported by defense money; their first encounters with computers were often in government-funded university labs. Yet by the time they graduated from college in the late 1960s and early 1970s, many of them wanted nothing to do with the military-industrial complex. So they seeded companies that repurposed technologies built for war to everyday life. They stayed in academia, moved into industrial research labs or started storefront computer-education centers and community message boards.

Then they founded computer companies infused with an ethos that was part counterculture, part cowboy. “The personal computer operator is the Electronic Man on Horseback riding into the (sinking) Western sun,” declared a columnist in the newsletter InfoWorld in 1980. “He is the last of the rugged individualists, and the personal computer is his only effective weapon.”

The military origins of modern tech gradually faded from view, but the business of war didn’t go away. The Pentagon remained the only place with the resources and the patience to fund blue-sky research that the market wasn’t quite ready for. Mr. Bezos knows this history well. His beloved grandfather Lawrence Preston Gise was one of the first employees of the Pentagon’s advanced research agency, Darpa. In the 1980s and 1990s, money from Darpa helped spur breakthroughs in high-speed networking, voice recognition and internet search. Today, it is funding research in artificial intelligence and machine learning, subterranean exploration and deep-space satellites, high-performance molecules and better GPS.

Whether their employees realize it or not, today’s tech giants all contain some defense-industry DNA. The result is the conflicted identity we now see in Silicon Valley.

But the American military’s heavy reliance on high-tech products means that backing away from defense work isn’t likely. There are fearsome national security threats, including cyberattacks on infrastructure and hacks of personal and electoral data, that cannot be overcome without a close partnership between the Pentagon and technology companies. These companies need to do more to explain to their employees and their customers what they are doing and why. This involves a much fuller reckoning with the long and complicated history of Silicon Valley and the business of war.

Margaret O’Mara, a professor of history at the University of Washington, is the author of a forthcoming book, “The Code: Silicon Valley and the Remaking of America.”