Agents: reaching private networks

How HCP Terraform agents run Terraform inside a private or on-premises network, pulling work over outbound connections only, so nothing on the inside has to be opened to the internet.

GazeekTERRAFORM AND PACKER: INFRASTRUCTURE AS CODE·LESSON 14
LESSON 14

Agents: reaching private networks

How HCP Terraform agents run Terraform inside a private or on-premises network, pulling work over outbound connections only, so nothing on the inside has to be opened to the internet.

0:00 / 3:51

Diagrams in this video · 2Free in archhy

Copy and edit in archhy: The agent calls out (new tab)
Copy and edit in archhy: An agent inside a private network (new tab)

After this lesson you can

  • Explain why HCP Terraform can't reach private infrastructure on its own
  • Describe how an agent polls for work over outbound connections
  • Explain agent pools and the agent execution mode
  • List what an agent host needs
Transcript

Agents: reaching private networks

Space Llama here. So far, HCP Terraform, on the HashiCorp Cloud Platform, has used run VMs, virtual machines, that call cloud APIs out on the internet. But some infrastructure lives behind a firewall. A private data center. A vSphere cluster. An internal API. Today, agents. How Terraform reaches the places the internet can't.

The problem

Remember, a remote run happens on HCP Terraform's own disposable virtual machines. To do its job, Terraform needs network access to every API it manages. A public cloud API is fine. But a private API, or an on-premises system, can't be reached from out there. You could open a hole in the firewall. Your security team would like a word about that.

The agent calls out

An agent turns the problem around. It's a small program you run inside your own network, next to the infrastructure it manages. The agent polls HCP Terraform, asking, any work for me? When a run is ready, it fetches it and runs Terraform locally. It needs only outbound connections to HCP Terraform. Nothing has to reach in. So the private network stays private, and the firewall stays shut.

An agent inside a private network

Here's the architecture. On the left, HCP Terraform, with its run queue and a workspace set to the agent execution mode. On the right, a private network, and in its private subnet, two agents. The arrows only go one way. Each agent connects out over HTTPS, and asks for work. Agent one has a run. It runs Terraform right here, calling a private API, like vSphere or an internal endpoint, which creates the private servers. Agent two is idle, waiting for the next job. The agent reports its progress and results back to HCP Terraform, again over outbound connections. So the run looks just like any other.

Agent pools

Agents are grouped into agent pools. Each pool usually covers one network. You set a workspace, or a whole project, to the agent execution mode, and choose its pool. When a run is queued, any available agent in that pool can take it. The plan and the apply might even run on different agents, so no agent should keep anything important on its own disk. Agents can also run hooks, small scripts at set points in a run, for example to download a tool the run needs.

What an agent needs

The agent runs on Linux, on x86 or ARM, or in HashiCorp's Docker container. Each pool has its own token, which an agent uses to join. Treat it like a password. The docs suggest at least 4 gigabytes of free disk and 2 gigabytes of memory, then sizing for your own workspaces. It needs outbound HTTPS to HCP Terraform, plus access to whatever APIs your Terraform code calls. How many agents you can run depends on your HCP Terraform edition.

Recap

Let's recap. Agents let HCP Terraform manage isolated, private or on-premises infrastructure. They poll for work over outbound connections only, so you open no inbound ports. Agents live in pools, and a workspace or project in agent execution mode sends its runs to a pool.

Practice and what's next

That's agents. Terraform, working from the inside, with the door still locked. To practice, try the free practice questions at Gazeek Labs. Next lesson, Drift, health and checks. See you there.

Gazeek Flash · free

Exam questions on your phone

Free questions on Guardrails and day two: quick-fire batches and timed exams, on the web or Android.