Skip to content

Commit 9e1d3d4

Browse files
backport of commit 09de8ff (#5906)
Co-authored-by: stellarsquall <[email protected]>
1 parent 48a36a3 commit 9e1d3d4

File tree

1 file changed

+146
-1
lines changed

1 file changed

+146
-1
lines changed

website/content/docs/configuration/target-aliases/create-target-alias.mdx

Lines changed: 146 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,22 @@ Complete the following steps to create a new alias and associate it with a targe
7575
The alias `value` can be a hostname or a DNS-like string.
7676
- `-authorize-session-host-id=<string>` - Optionally indicates the host ID to use when you use the alias to authorize a session.
7777

78+
</Tab>
79+
<Tab heading="Terraform" group="terraform">
80+
81+
Apply the following Terraform policy to create target alias `example.bar.foo.boundary` for an existing target `foo_target` and host `bar_host`:
82+
83+
```hcl
84+
resource "boundary_alias_target" "example_alias_target" {
85+
name = "example_alias_target"
86+
description = "Example alias to target foo using host boundary_host_static.bar_host"
87+
scope_id = "global"
88+
value = "example.bar.foo.boundary"
89+
destination_id = boundary_target.foo_target.id
90+
authorize_session_host_id = boundary_host_static.bar_host.id
91+
}
92+
```
93+
7894
</Tab>
7995
</Tabs>
8096

@@ -158,6 +174,67 @@ A value of `-1` means the connections are unlimited.
158174
Note that you can create SSH or TCP [target types](/boundary/docs/concepts/domain-model/targets#target-types).
159175
The example command in this section creates an SSH target.
160176

177+
</Tab>
178+
<Tab heading="Terraform" group="terraform">
179+
180+
Apply the following Terraform policy to create the following:
181+
182+
- A static host catalog `test_catalog` in `boundary_scope.project` (not shown) containing static host set `test_set`.
183+
- A host `foo` belonging to `test_set`.
184+
- A host `bar` belonging to `test_set`.
185+
- A target `foo_target` using `foo_set` as its host source.
186+
- A target alias `example.bar.foo.boundary` for `foo_target` that always uses `bar_host` to connect.
187+
188+
```hcl
189+
resource "boundary_host_catalog_static" "foo_catalog" {
190+
name = "foo_catalog"
191+
description = "test catalog"
192+
scope_id = boundary_scope.project.id
193+
}
194+
195+
resource "boundary_host_static" "foo_host" {
196+
name = "foo_host"
197+
host_catalog_id = boundary_host_catalog_static.foo.id
198+
address = "10.0.0.1"
199+
}
200+
201+
resource "boundary_host_static" "bar_host" {
202+
name = "bar_host"
203+
host_catalog_id = boundary_host_catalog_static.foo.id
204+
address = "127.0.0.1"
205+
}
206+
207+
resource "boundary_host_set_static" "foo_set" {
208+
name = "foo_set"
209+
host_catalog_id = boundary_host_catalog_static.foo_catalog.id
210+
211+
host_ids = [
212+
boundary_host_static.foo_host.id,
213+
boundary_host_static.bar_host.id,
214+
]
215+
}
216+
217+
resource "boundary_target" "foo_target" {
218+
name = "foo"
219+
description = "Foo target"
220+
type = "tcp"
221+
default_port = "22"
222+
scope_id = boundary_scope.project.id
223+
host_source_ids = [
224+
boundary_host_set_static.foo_set.id,
225+
]
226+
}
227+
228+
resource "boundary_alias_target" "example_alias_target" {
229+
name = "example_alias_target"
230+
description = "Example alias to target foo using host boundary_host_static.bar_host"
231+
scope_id = "global"
232+
value = "example.bar.foo.boundary"
233+
destination_id = boundary_target.foo_target.id
234+
authorize_session_host_id = boundary_host_static.bar_host.id
235+
}
236+
```
237+
161238
</Tab>
162239
</Tabs>
163240

@@ -210,6 +287,22 @@ If you [created an alias](#create-an-alias-for-an-existing-target) without assoc
210287
The alias `value` must comply with DNS naming rules.
211288
- `-authorize-session-host-id=<string>` - Optionally indicates the host ID to use when you use the alias to authorize a session.
212289

290+
</Tab>
291+
<Tab heading="Terraform" group="terraform">
292+
293+
If you created a `boundary_alias_target` resource without setting a `destination_id` attribute, update the `destination_id` and reapply the following policy:
294+
295+
```hcl
296+
resource "boundary_alias_target" "example_alias_target" {
297+
name = "example_alias_target"
298+
description = "Example alias to target foo using host boundary_host_static.bar_host"
299+
scope_id = "global"
300+
value = "example.bar.foo.boundary"
301+
destination_id = boundary_target.foo_target.id
302+
authorize_session_host_id = boundary_host_static.bar_host.id
303+
}
304+
```
305+
213306
</Tab>
214307
</Tabs>
215308

@@ -252,7 +345,7 @@ And the following host set and hosts exist:
252345
- Host: `dev-040`, ID `hst_7wGXkF8e0Q`
253346
- Host: `dev-041`, ID `hst_zlRwMMPKwp`
254347

255-
Because the `linux-dev-servers` hosts are functionally equivalent, you can create a single target for the host set, and create an alias for the target.
348+
Because the `linux-dev-servers` hosts are functionally equivalent, you can create a single target for the host set, and create an alias for the target.
256349

257350
We recommend creating DNS-like aliases to ensure consistent naming conventions. In this example, an alias pattern might be:
258351

@@ -362,6 +455,30 @@ Then add the `linux-dev-servers` host set (ID `hsst_56oiL0WaKu`) to the new `lin
362455
$ boundary targets add-host-sources -id tssh_lhH5pa425G -host-sourchsst_56oiL0WaKu
363456
```
364457

458+
</Tab>
459+
<Tab heading="Terraform" group="terraform">
460+
461+
<Note>
462+
463+
In the following examples, Terraform resources are named with underscores instead of dashes, such as `linux_dev_servers`. The target alias values use dashes, such as `dev-041.linux-dev.app-servers.eng`. You do not need to follow these naming conventions.
464+
465+
</Note>
466+
467+
Create the `linux_dev_servers` SSH target, with `scope_id` set to `app_servers` and the host source `linux_dev_servers` (these resources are not shown):
468+
469+
```hcl
470+
resource "boundary_target" "linux_dev_servers" {
471+
name = "linux_dev_servers"
472+
description = "linux_dev_servers target"
473+
type = "ssh"
474+
default_port = "22"
475+
scope_id = boundary_scope.app_servers.id
476+
host_source_ids = [
477+
boundary_host_set_static.linux_dev_servers.id,
478+
]
479+
}
480+
```
481+
365482
</Tab>
366483
</Tabs>
367484

@@ -444,6 +561,20 @@ Create the `dev-040.linux-dev.app-servers.eng` alias for the host `dev-040`:
444561

445562
</CodeBlockConfig>
446563

564+
</Tab>
565+
<Tab heading="Terraform" group="terraform">
566+
567+
```hcl
568+
resource "boundary_alias_target" "dev_040" {
569+
name = "dev_040"
570+
description = "Example alias for target linux_dev_servers using host dev_040"
571+
scope_id = "global"
572+
value = "dev-040.linux-dev.app-servers.eng"
573+
destination_id = boundary_target.linux_dev_servers.id
574+
authorize_session_host_id = boundary_host_static.dev_040.id
575+
}
576+
```
577+
447578
</Tab>
448579
</Tabs>
449580

@@ -524,6 +655,20 @@ Then create the `dev-041.linux-dev.app-servers.eng` alias for the host `dev-041`
524655

525656
</CodeBlockConfig>
526657

658+
</Tab>
659+
<Tab heading="Terraform" group="terraform">
660+
661+
```hcl
662+
resource "boundary_alias_target" "dev_041" {
663+
name = "dev_040"
664+
description = "Example alias for target linux_dev_servers using host dev_040"
665+
scope_id = "global"
666+
value = "dev-041.linux-dev.app-servers.eng"
667+
destination_id = boundary_target.linux_dev_servers.id
668+
authorize_session_host_id = boundary_host_static.dev_041.id
669+
}
670+
```
671+
527672
</Tab>
528673
</Tabs>
529674

0 commit comments

Comments
 (0)