Skip to content

Commit

Permalink
test(e2e): Add support for an hcp worker
Browse files Browse the repository at this point in the history
  • Loading branch information
moduli committed Jul 23, 2024
1 parent aafdcd8 commit 7cc0548
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 13 deletions.
8 changes: 8 additions & 0 deletions enos/enos-variables.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,11 @@ variable "go_version" {
type = string
default = ""
}

variable "hcp_boundary_cluster_id" {
description = "ID of the Boundary cluster in HCP"
type = string
default = ""
// If using HCP int, ensure that the cluster id starts with "int-"
// Example: "int-19283a-123123-..."
}
33 changes: 23 additions & 10 deletions enos/modules/aws_boundary/boundary-instances.tf
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ resource "enos_file" "controller_config" {
}

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

bin_name = var.boundary_binary_name
bin_path = var.boundary_install_dir
Expand All @@ -133,7 +133,7 @@ resource "enos_boundary_init" "controller" {

transport = {
ssh = {
host = aws_instance.controller[0].public_ip
host = try(aws_instance.controller[0].public_ip, null)
}
}

Expand Down Expand Up @@ -217,14 +217,15 @@ resource "enos_file" "worker_config" {
depends_on = [enos_bundle_install.worker]
destination = "/etc/boundary/boundary.hcl"
content = templatefile("${path.module}/${var.worker_config_file_path}", {
id = each.value
kms_key_id = data.aws_kms_key.kms_key.id,
controller_ips = jsonencode(aws_instance.controller.*.private_ip),
public_addr = aws_instance.worker[tonumber(each.value)].public_ip
region = var.aws_region
type = jsonencode(var.worker_type_tags)
recording_storage_path = var.recording_storage_path
audit_log_dir = local.audit_log_directory
id = each.value
kms_key_id = data.aws_kms_key.kms_key.id,
controller_ips = jsonencode(aws_instance.controller.*.private_ip),
public_addr = aws_instance.worker[tonumber(each.value)].public_ip
region = var.aws_region
type = jsonencode(var.worker_type_tags)
recording_storage_path = var.recording_storage_path
audit_log_dir = local.audit_log_directory
hcp_boundary_cluster_id = var.hcp_boundary_cluster_id
})
for_each = toset([for idx in range(var.worker_count) : tostring(idx)])

Expand Down Expand Up @@ -271,3 +272,15 @@ resource "enos_remote_exec" "create_worker_audit_log_dir" {
}
}
}

resource "enos_remote_exec" "get_worker_token" {
depends_on = [enos_boundary_start.worker_start]
for_each = var.hcp_boundary_cluster_id != "" ? toset([for idx in range(var.worker_count) : tostring(idx)]) : []

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'"]
transport = {
ssh = {
host = aws_instance.worker[tonumber(each.value)].public_ip
}
}
}
7 changes: 7 additions & 0 deletions enos/modules/aws_boundary/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,10 @@ output "pet_id" {
description = "The ID of the random_pet used in this module"
value = random_pet.default.id
}

output "worker_tokens" {
description = "If available, worker tokens used to register to Boundary"
value = try([
for token in enos_remote_exec.get_worker_token : trimspace(token.stdout)
], null)
}
2 changes: 1 addition & 1 deletion enos/modules/aws_boundary/security-groups.tf
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ resource "aws_security_group" "boundary_alb_sg" {
cidr_blocks = flatten([
formatlist("%s/32", data.enos_environment.localhost.public_ipv4_addresses),
join(",", data.aws_vpc.infra.cidr_block_associations.*.cidr_block),
format("%s/32", aws_instance.controller.0.public_ip),
try(format("%s/32", aws_instance.controller.0.public_ip), []),
formatlist("%s/32", var.alb_sg_additional_ips)
])
description = ingress.key
Expand Down
63 changes: 63 additions & 0 deletions enos/modules/aws_boundary/templates/worker_hcp_bsr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: BUSL-1.1

listener "tcp" {
purpose = "proxy"
tls_disable = true
address = "0.0.0.0"
}

hcp_boundary_cluster_id = "${hcp_boundary_cluster_id}"

worker {
public_addr = "${public_addr}"

tags {
type = ${type}
region = ["${region}"]
}

auth_storage_path = "/tmp/boundary/worker"
recording_storage_path = "${recording_storage_path}"
}

events {
audit_enabled = true
observations_enabled = true
sysevents_enabled = true

sink "stderr" {
name = "all-events"
description = "All events sent to stderr"
event_types = ["*"]
format = "cloudevents-json"

deny_filters = [
"\"/data/request_info/method\" contains \"Status\"",
"\"/data/request_info/path\" contains \"/health\"",
]
}

sink {
name = "audit-sink"
description = "Audit sent to a file"
event_types = ["audit"]
format = "cloudevents-json"

deny_filters = [
"\"/data/request_info/method\" contains \"Status\"",
]

file {
path = "${audit_log_dir}"
file_name = "audit.log"
}

audit_config {
audit_filter_overrides {
secret = "encrypt"
sensitive = "hmac-sha256"
}
}
}
}
8 changes: 8 additions & 0 deletions enos/modules/aws_boundary/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,11 @@ variable "recording_storage_path" {
type = string
default = ""
}

variable "hcp_boundary_cluster_id" {
description = "ID of the Boundary cluster in HCP"
type = string
default = ""
// If using HCP int, ensure that the cluster id starts with "int-"
// Example: "int-19283a-123123-..."
}
3 changes: 1 addition & 2 deletions enos/modules/aws_iam_setup/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ output "access_key_id" {
}

output "secret_access_key" {
value = aws_iam_access_key.boundary.secret
sensitive = true
value = nonsensitive(aws_iam_access_key.boundary.secret)
}

output "user_name" {
Expand Down

0 comments on commit 7cc0548

Please sign in to comment.