refact(e2e): Port enos smoke test into e2e test suite

This adds a test case to the e2e test suite and unifies where testing is located.
This commit is contained in:
Michael Li committed 2022-10-12 09:49:08 -04:00
1 parent 1361c3cc6d
commit 5365b29007
6 files changed
+258 -206

No files matched your search

+1 -36
View File
@@ -43,7 +43,7 @@ scenario "integration" {
matrix {
builder = ["local", "crt"]
test = ["smoke", "cli_ui"]
test = ["cli_ui"]
}
locals {
@@ -120,41 +120,6 @@ scenario "integration" {
}
}
step "launch_smoke_targets" {
skip_step = matrix.test != "smoke"
module = module.target
depends_on = [step.create_base_infra]
variables {
ami_id = step.create_base_infra.ami_ids["ubuntu"]["amd64"]
aws_ssh_keypair_name = var.aws_ssh_keypair_name
enos_user = var.enos_user
instance_type = var.target_instance_type
vpc_id = step.create_base_infra.vpc_id
}
}
step "run_test_smoke" {
skip_step = matrix.test != "smoke"
module = module.test_smoke
depends_on = [step.create_boundary_cluster]
variables {
alb_boundary_api_addr = step.create_boundary_cluster.alb_boundary_api_addr
auth_login_name = step.create_boundary_cluster.auth_login_name
auth_method_id = step.create_boundary_cluster.auth_method_id
auth_password = step.create_boundary_cluster.auth_password
aws_ssh_private_key_path = local.aws_ssh_private_key_path
boundary_install_dir = local.boundary_install_dir
controller_ips = step.create_boundary_cluster.controller_ips
local_boundary_dir = local.local_boundary_dir
project_scope_id = step.create_boundary_cluster.project_scope_id
target_count = var.target_count
target_id = step.create_boundary_cluster.target_id
target_ips = step.launch_smoke_targets.target_ips
}
}
step "run_test_cli_ui" {
skip_step = matrix.test != "cli_ui"
module = module.test_cli_ui
-5
View File
@@ -1,5 +0,0 @@
# Smoke Test
This test runs a basic smoke test that gets a Boundary Auth token, creates a
test catalog and host set, adds the "target" node(s) as hosts/targets and
attempts to SSH to a target to verify that it is able.
-140
View File
@@ -1,140 +0,0 @@
terraform {
required_providers {
enos = {
source = "app.terraform.io/hashicorp-qti/enos"
}
}
}
variable "alb_boundary_api_addr" {}
variable "auth_login_name" {}
variable "auth_method_id" {}
variable "auth_password" {}
variable "aws_ssh_private_key_path" {}
variable "boundary_install_dir" {}
variable "controller_ips" {}
variable "local_boundary_dir" {}
variable "project_scope_id" {}
variable "target_count" {}
variable "target_id" {}
variable "target_ips" {}
resource "enos_local_exec" "local_boundary_version" {
inline = ["${var.local_boundary_dir}/boundary version -format=json"]
}
resource "enos_remote_exec" "remote_boundary_version" {
inline = ["${var.boundary_install_dir}/boundary version -format=json"]
transport = {
ssh = {
host = var.controller_ips.0
}
}
}
locals {
base_environment = {
BOUNDARY_ADDR = var.alb_boundary_api_addr,
BOUNDARY_TOKEN = local.auth_token
}
}
resource "enos_local_exec" "get_token" {
environment = {
BOUNDARY_ADDR = var.alb_boundary_api_addr,
BOUNDARY_PATH = var.local_boundary_dir,
METHOD_ID = var.auth_method_id,
LOGIN_NAME = var.auth_login_name,
PASSWORD = var.auth_password,
}
scripts = ["${path.module}/../../templates/get-token.sh"]
}
locals {
auth_token = jsondecode(enos_local_exec.get_token.stdout).item.attributes.token
}
resource "enos_local_exec" "read_target" {
environment = local.base_environment
inline = ["${var.local_boundary_dir}/boundary targets read -id ${var.target_id}"]
}
resource "enos_local_exec" "create_catalog" {
environment = local.base_environment
inline = ["${var.local_boundary_dir}/boundary host-catalogs create static -scope-id=${var.project_scope_id} -name=enos1 -description=test -format=json"]
}
locals {
catalog_id = jsondecode(enos_local_exec.create_catalog.stdout).item.id
}
resource "enos_local_exec" "create_static_hosts" {
environment = local.base_environment
for_each = toset([for idx in range(var.target_count) : tostring(idx)])
inline = ["${var.local_boundary_dir}/boundary hosts create static -name=${var.target_ips[each.value]} -description=${var.target_ips[each.value]} -address=${var.target_ips[each.value]} -host-catalog-id=${local.catalog_id} -format=json"]
}
locals {
host_ids = [for idx in range(var.target_count) : jsondecode(values(enos_local_exec.create_static_hosts)[idx].stdout).item.id]
}
resource "enos_local_exec" "create_host_set" {
environment = local.base_environment
inline = ["${var.local_boundary_dir}/boundary host-sets create static -name='test-machines' -description='Test machine host set' -host-catalog-id=${local.catalog_id} -format=json"]
}
locals {
host_set_id = jsondecode(enos_local_exec.create_host_set.stdout).item.id
}
resource "enos_local_exec" "add_to_host_set" {
environment = local.base_environment
for_each = toset([for idx in range(var.target_count) : tostring(idx)])
inline = ["${var.local_boundary_dir}/boundary host-sets add-hosts -id=${local.host_set_id} -host=${local.host_ids[each.value]} -format=json"]
}
resource "enos_local_exec" "create_static_credential_store" {
environment = local.base_environment
inline = ["${var.local_boundary_dir}/boundary credential-stores create static -scope-id=${var.project_scope_id} -format=json"]
}
locals {
credential_store_id = jsondecode(enos_local_exec.create_static_credential_store.stdout).item.id
}
resource "enos_local_exec" "create_ssh_private_key_credential" {
environment = local.base_environment
inline = ["${var.local_boundary_dir}/boundary credentials create ssh-private-key -credential-store-id=${local.credential_store_id} -username=ubuntu -private-key=file://${var.aws_ssh_private_key_path} -format=json"]
}
locals {
credential_id = jsondecode(enos_local_exec.create_ssh_private_key_credential.stdout).item.id
}
resource "enos_local_exec" "create_target" {
environment = local.base_environment
inline = ["${var.local_boundary_dir}/boundary targets create tcp -name='test target' -description='test target' -default-port=22 -scope-id=${var.project_scope_id} -session-connection-limit='-1' -session-max-seconds=900 -format=json"]
}
locals {
target_id = jsondecode(enos_local_exec.create_target.stdout).item.id
}
resource "enos_local_exec" "add_hosts_to_target" {
environment = local.base_environment
inline = ["${var.local_boundary_dir}/boundary targets add-host-sources -id=${local.target_id} -host-source=${local.host_set_id} -format=json"]
}
resource "enos_local_exec" "add_credential_to_target" {
environment = local.base_environment
inline = ["${var.local_boundary_dir}/boundary targets add-credential-sources -id=${local.target_id} -brokered-credential-source=${local.credential_id} -format=json"]
}
resource "enos_local_exec" "connect_target" {
environment = merge(local.base_environment,
{
BOUNDARY_PATH = var.local_boundary_dir
TARGET_ID = local.target_id
})
scripts = ["${path.module}/../../templates/connect-target.sh"]
}
-24
View File
@@ -1,24 +0,0 @@
#!/bin/bash
set -e
function retry {
local retries=$1
shift
local count=0
until "$@"; do
exit=$?
wait=$((2 ** count))
count=$((count + 1))
if [ "$count" -lt "$retries" ]; then
sleep "$wait"
else
return "$exit"
fi
done
return 0
}
retry 10 ${BOUNDARY_PATH}/boundary connect ssh -target-id=${TARGET_ID} -- -o StrictHostKeyChecking=no