---
layout: docs
page_title: Manage Targets
sidebar_title: Manage Targets
description: How to manage Boundary targets
---

# Manage Targets

[Targets](/docs/concepts/domain-model/targets) are Boundary resources which contain a [host-set](/docs/concepts/domain-model/host-sets). A target allows Boundary users to define an endpoint with a default-port and a protocol to establish a session. Unless specified with a `-host-id` flag, Boundary will choose one [host](/docs/concepts/domain-model/hosts) in the host-set to connect to at random.

In this section, we'll show you the basics of how to define a host, host-set, and a target in Boundary on the CLI, the admin console, and using our [Terraform provider](https://github.com/hashicorp/terraform-provider-boundary).

We assume you're running Boundary in dev mode and have a default static host-catalog of `hcst_1234567890`. We also assume you've logged in on the command line and the admin console. See the output of `boundary dev` for these login values.

~> Note that all resource ID's in this example are illustration only - ID's are uniquely generated for every resource upon creation with the exception being
generated resources in `dev mode`. Please make sure to use the resource ID's that are generated when running this example. For example, if you run
`boundary users create`, use the resource ID of the user seen in stdout, not the ID in the example command.

## Define a Host

For this example, we're going to create a target to access postgres on `localhost`. This assumes a couple of things:

1. The host address is `127.0.0.1`
2. The target port is `:5432`

<Tabs>
<Tab heading="CLI">


```bash
boundary hosts create static -name postgres -description "Postgres host" -address "127.0.0.1" -host-catalog-id "hcst_1234567890"

Host information:
  Created Time:        Mon, 28 Sep 2020 18:12:39 PDT
  Description:         Postgres host
  Host Catalog ID:     hcst_1234567890
  ID:                  hst_N5l67hLYrQ
  Name:                postgres
  Type:                static
  Updated Time:        Mon, 28 Sep 2020 18:12:39 PDT
  Version:             1

  Scope:
    ID:                p_1234567890
    Name:              Generated project scope
    Parent Scope ID:   o_1234567890
    Type:              project

  Attributes:
    address:           127.0.0.1
```

</Tab>
<Tab heading="Admin Console">


Navigate to the default host catalog:
![](/img/manage-targets-host-undefined.png)

Select new host from the `manage` dropdown:
![](/img/manage-targets-new-host.png)

Fill in the required information about our postgres host:
![](/img/manage-targets-new-host-2.png)

View the host in the catalog:
![](/img/manage-targets-new-host-defined.png)

</Tab>
<Tab heading="Terraform">


To define this same host using our Terraform provider:

```hcl
resource "boundary_host" "postgres" {
  type            = "static"
  name            = "postgres"
  description     = "Postgres host"
  address         = "127.0.0.1"
  host_catalog_id = "hcst_1234567890"
}
```

</Tab>
</Tabs>


## Define a Host-Set

Host-sets allow us to group hosts of similar interests together. A target works off of host-sets, so even though we are only defining one host in this example, we're going to create a host-set of one host.

<Tabs>
<Tab heading="CLI">


```bash
boundary host-sets create static -name "postgres" -description "Postgres host set" -host-catalog-id hcst_1234567890

Host Set information:
  Created Time:        Mon, 28 Sep 2020 18:27:10 PDT
  Description:         Postgres host set
  Host Catalog ID:     hcst_1234567890
  ID:                  hsst_z7gDCPSig5
  Name:                postgres
  Type:                static
  Updated Time:        Mon, 28 Sep 2020 18:27:10 PDT
  Version:             1

  Scope:
    ID:                p_1234567890
    Name:              Generated project scope
    Parent Scope ID:   o_1234567890
    Type:              project
```

</Tab>
<Tab heading="Admin Console">


Navigate to the host catalog and the `host sets` tab, select `Create Host Set` from `manage` dropdown:
![](/img/manage-targets-new-host-set-undefined.png)

Fill in the host-set definition:
![](/img/manage-targets-new-host-set-settings.png)

See the new host set in the host-catalog view:
![](/img/manage-targets-new-host-set-defined.png)

</Tab>
<Tab heading="Terraform">


To define this host-set in Terraform:

```hcl
resource "boundary_host_set" "postgres" {
  type            = "static"
  name            = "postgres"
  description     = "Host set for postgres"
  host_catalog_id = host_catalog_id = "hcst_1234567890"

  // taken from the Terraform example above
  host_ids = [ boundary_host.postgres.id ]
}
```

</Tab>
</Tabs>


## Define a Target

<Tabs>
<Tab heading="CLI">


```bash
boundary targets create tcp -name 'postgres' -description 'Postgres target' -default-port 5432 -scope-id p_1234567890 -session-connection-limit '-1'

Target information:
  Created Time:               Mon, 28 Sep 2020 18:43:12 PDT
  Description:                Postgres target
  ID:                         ttcp_CzVQA3adBf
  Name:                       postgres
  Session Connection Limit:   -1
  Session Max Seconds:        28800
  Type:                       tcp
  Updated Time:               Mon, 28 Sep 2020 18:43:12 PDT
  Version:                    1

  Scope:
    ID:                       p_1234567890
    Name:                     Generated project scope
    Parent Scope ID:          o_1234567890
    Type:                     project
  Attributes:
    Default Port:             5432
```

</Tab>
<Tab heading="Admin Console">


Navigate to your the default project:
![](/img/manage-targets-new-target-project.png)

Then the targets view and choose `new` target:
![](/img/manage-targets-new-target-undefined.png)

Fill in the Target info:
![](/img/manage-targets-new-target-settings.png)

See the Target in the targets view:
![](/img/manage-targets-new-target-defined.png)

</Tab>
<Tab heading="Terraform">


To define this target in Terraform:

```hcl
resource "boundary_target" "postgres" {
  type                     = "tcp"
  name                     = "postgres"
  description              = "Postgres target"
  scope_id                 = "p_1234567890"
  session_connection_limit = -1
  default_port             = 5432

  // taken from the example above
  host_set_ids = [
    boundary_host_set.postgres.id
  ]
}
```

</Tab>
</Tabs>

