Skip to content

Commit edd7ec6

Browse files
authored
test(e2e): Add support for an hcp worker (#4939)
1 parent 85f98a4 commit edd7ec6

File tree

7 files changed

+111
-13
lines changed

7 files changed

+111
-13
lines changed

enos/enos-variables.hcl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,11 @@ variable "go_version" {
192192
type = string
193193
default = ""
194194
}
195+
196+
variable "hcp_boundary_cluster_id" {
197+
description = "ID of the Boundary cluster in HCP"
198+
type = string
199+
default = ""
200+
// If using HCP int, ensure that the cluster id starts with "int-"
201+
// Example: "int-19283a-123123-..."
202+
}

enos/modules/aws_boundary/boundary-instances.tf

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ resource "enos_file" "controller_config" {
124124
}
125125

126126
resource "enos_boundary_init" "controller" {
127-
count = local.is_restored_db ? 0 : 1 // init not required when we restore from a snapshot
127+
count = !local.is_restored_db && var.controller_count > 0 ? 1 : 0 // init not required when we restore from a snapshot
128128

129129
bin_name = var.boundary_binary_name
130130
bin_path = var.boundary_install_dir
@@ -133,7 +133,7 @@ resource "enos_boundary_init" "controller" {
133133

134134
transport = {
135135
ssh = {
136-
host = aws_instance.controller[0].public_ip
136+
host = try(aws_instance.controller[0].public_ip, null)
137137
}
138138
}
139139

@@ -217,14 +217,15 @@ resource "enos_file" "worker_config" {
217217
depends_on = [enos_bundle_install.worker]
218218
destination = "/etc/boundary/boundary.hcl"
219219
content = templatefile("${path.module}/${var.worker_config_file_path}", {
220-
id = each.value
221-
kms_key_id = data.aws_kms_key.kms_key.id,
222-
controller_ips = jsonencode(aws_instance.controller.*.private_ip),
223-
public_addr = aws_instance.worker[tonumber(each.value)].public_ip
224-
region = var.aws_region
225-
type = jsonencode(var.worker_type_tags)
226-
recording_storage_path = var.recording_storage_path
227-
audit_log_dir = local.audit_log_directory
220+
id = each.value
221+
kms_key_id = data.aws_kms_key.kms_key.id,
222+
controller_ips = jsonencode(aws_instance.controller.*.private_ip),
223+
public_addr = aws_instance.worker[tonumber(each.value)].public_ip
224+
region = var.aws_region
225+
type = jsonencode(var.worker_type_tags)
226+
recording_storage_path = var.recording_storage_path
227+
audit_log_dir = local.audit_log_directory
228+
hcp_boundary_cluster_id = var.hcp_boundary_cluster_id
228229
})
229230
for_each = toset([for idx in range(var.worker_count) : tostring(idx)])
230231

@@ -271,3 +272,15 @@ resource "enos_remote_exec" "create_worker_audit_log_dir" {
271272
}
272273
}
273274
}
275+
276+
resource "enos_remote_exec" "get_worker_token" {
277+
depends_on = [enos_boundary_start.worker_start]
278+
for_each = var.hcp_boundary_cluster_id != "" ? toset([for idx in range(var.worker_count) : tostring(idx)]) : []
279+
280+
inline = ["timeout 10s bash -c 'set -eo pipefail; until journalctl -u boundary.service | cat | grep \"Worker Auth Registration Request: .*\" | rev | cut -d \" \" -f 1 | rev | xargs; do sleep 2; done'"]
281+
transport = {
282+
ssh = {
283+
host = aws_instance.worker[tonumber(each.value)].public_ip
284+
}
285+
}
286+
}

enos/modules/aws_boundary/outputs.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,10 @@ output "pet_id" {
225225
description = "The ID of the random_pet used in this module"
226226
value = random_pet.default.id
227227
}
228+
229+
output "worker_tokens" {
230+
description = "If available, worker tokens used to register to Boundary"
231+
value = try([
232+
for token in enos_remote_exec.get_worker_token : trimspace(token.stdout)
233+
], null)
234+
}

enos/modules/aws_boundary/security-groups.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ resource "aws_security_group" "boundary_alb_sg" {
8888
cidr_blocks = flatten([
8989
formatlist("%s/32", data.enos_environment.localhost.public_ipv4_addresses),
9090
join(",", data.aws_vpc.infra.cidr_block_associations.*.cidr_block),
91-
format("%s/32", aws_instance.controller.0.public_ip),
91+
try(format("%s/32", aws_instance.controller.0.public_ip), []),
9292
formatlist("%s/32", var.alb_sg_additional_ips)
9393
])
9494
description = ingress.key
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Copyright (c) HashiCorp, Inc.
2+
# SPDX-License-Identifier: BUSL-1.1
3+
4+
listener "tcp" {
5+
purpose = "proxy"
6+
tls_disable = true
7+
address = "0.0.0.0"
8+
}
9+
10+
hcp_boundary_cluster_id = "${hcp_boundary_cluster_id}"
11+
12+
worker {
13+
public_addr = "${public_addr}"
14+
15+
tags {
16+
type = ${type}
17+
region = ["${region}"]
18+
}
19+
20+
auth_storage_path = "/tmp/boundary/worker"
21+
recording_storage_path = "${recording_storage_path}"
22+
}
23+
24+
events {
25+
audit_enabled = true
26+
observations_enabled = true
27+
sysevents_enabled = true
28+
29+
sink "stderr" {
30+
name = "all-events"
31+
description = "All events sent to stderr"
32+
event_types = ["*"]
33+
format = "cloudevents-json"
34+
35+
deny_filters = [
36+
"\"/data/request_info/method\" contains \"Status\"",
37+
"\"/data/request_info/path\" contains \"/health\"",
38+
]
39+
}
40+
41+
sink {
42+
name = "audit-sink"
43+
description = "Audit sent to a file"
44+
event_types = ["audit"]
45+
format = "cloudevents-json"
46+
47+
deny_filters = [
48+
"\"/data/request_info/method\" contains \"Status\"",
49+
]
50+
51+
file {
52+
path = "${audit_log_dir}"
53+
file_name = "audit.log"
54+
}
55+
56+
audit_config {
57+
audit_filter_overrides {
58+
secret = "encrypt"
59+
sensitive = "hmac-sha256"
60+
}
61+
}
62+
}
63+
}

enos/modules/aws_boundary/variables.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,11 @@ variable "recording_storage_path" {
370370
type = string
371371
default = ""
372372
}
373+
374+
variable "hcp_boundary_cluster_id" {
375+
description = "ID of the Boundary cluster in HCP"
376+
type = string
377+
default = ""
378+
// If using HCP int, ensure that the cluster id starts with "int-"
379+
// Example: "int-19283a-123123-..."
380+
}

enos/modules/aws_iam_setup/main.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ output "access_key_id" {
7373
}
7474

7575
output "secret_access_key" {
76-
value = aws_iam_access_key.boundary.secret
77-
sensitive = true
76+
value = nonsensitive(aws_iam_access_key.boundary.secret)
7877
}
7978

8079
output "user_name" {

0 commit comments

Comments
 (0)