Configure self-hosted Boundary using Terraform
With Boundary is still running in dev mode, you are going to use Terraform to configure your Boundary environment.
This tutorial will configure the following resources:
Type | Name | Notes |
---|---|---|
Organization | corp_one | A new organization |
Users | (multiple) | Creates 9 users (Jim, Jeff, Randy, etc.) |
Group | read-only | A new group with 3 users |
Roles | (multiple) | 2 new roles (Read-only and admin) |
Auth Method | Corp Password | A new password auth method |
Project | core_infra | A new project within the corp_one organization |
Host catalog | backend_servers | A new host catalog with one host set |
Host set | backend_servers_ssh | A new host set with 2 hosts |
Targets | (multiple) | 2 new targets (ssh_server and backend_server) |
Prerequisites
- Terraform 0.13.0 or later installed
- Boundary is still running in dev mode
Background
Terraform is an infrastructure automation tool that makes provisioning resources simple and repeatable. The process of configuring Boundary resources using the CLI can be tedious and time-intensive. Using Terraform, setting up the resources needed for a Boundary deployment can be simplified and easily repeated at scale.
This tutorial uses version 1.0.10 of the official Boundary provider in the Terraform registry. Other Terraform modules exist that simplify the process of standing up an environment further, such as the getting-started module that deploys everything needed for first log in.
Configure Boundary
To get started, create a directory named, boundary-test
.
Create a Terraform configuration file, main.tf
and paste in the following.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
The Terraform resources in this configuration map to these Boundary resources:
- boundary_scope (line 37) -> A Scope is a permission boundary modeled as a container.
- boundary_auth_method (line 52) -> An auth method provides a mechanism for users to authenticate to Boundary.
- boundary_account_password (line 58) -> An account represents a unique set of credentials issued from a configured authentication method which can be used to establish the identity of a user.
- boundary_user (line 68) -> A user represents an individual person or entity for the purposes of access control.
- boundary_group (line 82) -> A group represents a collection of users which can be treated equally for the purposes of access control.
- boundary_role (line 97) -> A role contains a collection of permissions which are granted to any principal assigned to the role.
- boundary_host_catalog_static (line 114) -> A static host catalog contains hosts and host sets.
- boundary_host_static (line 121) -> A static host represents a computing element with a network address reachable from Boundary.
- boundary_host_set_static (line 130) -> A static host set represents a collection of hosts which are considered equivalent for the purposes of access control.
- boundary_target (line 152) -> A target represents a networked service with an associated set of permissions a user can connect to and interact with through Boundary by way of a session.
For more detail description and example for each resource, refer to the Terraform Boundary provider documentation.
Now, you are ready to initialize Terraform.
The init
command downloads the latest available Terraform Provider for
Boundary. Alternatively, you can clone the Terraform Boundary Provider GitHub
repository and build
it from the source code. Refer to its README for more detail.
Run terraform apply
and review the planned actions. Your terminal output
should indicate the plan is running and what resources will be created.
Enter yes
to confirm and resume.
When it completes, you should see "Apply complete" message. Any warnings about deprecated attributes can be ignored for this example.
From the admin console, select the newly created corp_one organization, and verify that Terraform created users, groups, roles and other resources.
Connecting to Targets
The boundary connect
command can be used to establish sessions with hosts that
Boundary manages. First, log into Boundary as the admin
user. Enter the
password password
when prompted.
Next, find the names of all the available scopes using recursive listing.
Copy the corp_one Scope ID, and use recursive listing again to find all the available targets in the new scope.
Two tcp targets are available, ssh_server
and backend_server
.
It's important to note that these targets do not actually exist in this dev environment; the targets have simply been added to the Boundary host catalog using Terraform. In a more realistic scenario these targets would have first been provisioned, and then added to Boundary.
Sessions can be established to targets using the boundary connect
command.
There are several built-in sub-commands for accessing targets with specific
protocols.
Subcommands:
http
Authorize a session against a target and invoke an HTTP client to connectkube
Authorize a session against a target and invoke a Kubernetes client to connectpostgres
Authorize a session against a target and invoke a Postgres client to connectrdp
Authorize a session against a target and invoke an RDP client to connectssh
Authorize a session against a target and invoke an SSH client to connect
Start by establishing an ssh connection to the Backend SSH target using boundary connect
.
The pending connection will hang as a session is attempted. Remember, these
targets do not actually exist, so this demonstration simply shows how the
boundary connect
command can be used against targets in the host catalog.
The pending connection can be viewed by recursively listing the sessions.
The session can be canceled using the boundary sessions
command and providing
the session ID.
Verify that the session shows Status: Terminated
by running boundary sessions list -recursive
again.
Targets can be addressed directly using the -target-id
option, or using a
combination of the -target-name
and -target-scope-name
options if you
provide the project name that the target exists within (core_infra, in this
example).
Try this workflow with the other target, backend_server
. The boundary connect
command can be used for generic tcp connections, without the protocol
sub-command.
Again, the session will hang as a connection is attempted with the target. Like
the previous example with the SSH target, verify the pending connection, and
then cancel it using the boundary sessions
command.
Warning
You man encounter the following error when running boundary connect
:
Warning
If you check the terminal window where boundary dev
was run, you may see a
log entry related to runtime memory.
Warning
This implies that the Boundary controller started with dev mode has run out
of memory. This can occur after running too many connections agains the dev
sever, or by re-provisioning too many times. Simply stop dev mode by entering
Ctrl+C, start dev mode again with boundary dev
, and run terraform apply --auto-approve
to set up the environment again.
You can edit the Terraform configuration file (main.tf
) to make changes,
and then run terraform apply
again to commit the changes. Terraform stores
state about your managed infrastructure and configuration which is used to map
real world resources to your configuration, keep track of metadata, and to
improve performance for large infrastructures. To learn more about Terraform,
visit Terraform Learn.
To stop the Boundary dev server, enter Ctrl+C in the terminal where it is running.