test(e2e): Add dynamic host catalog test (AWS)
This adds the initial set of tests that validate setting up a dynamic host catalog on AWS Co-authored-by: Josh Brand <jbrand@hashicorp.com>
This commit is contained in:
1 parent
da885a89c3
commit
da0fb9d38a
19 files changed
+1035
-291
No files matched your search
+16
-8
@@ -2,6 +2,10 @@ module "az_finder" {
|
||||
source = "./modules/az_finder"
|
||||
}
|
||||
|
||||
module "bats_deps" {
|
||||
source = "./modules/bats_deps"
|
||||
}
|
||||
|
||||
module "binary_finder" {
|
||||
source = "./modules/binary_finder"
|
||||
}
|
||||
@@ -23,10 +27,6 @@ module "boundary" {
|
||||
alb_listener_api_port = var.alb_listener_api_port
|
||||
}
|
||||
|
||||
module "bats_deps" {
|
||||
source = "./modules/bats_deps"
|
||||
}
|
||||
|
||||
module "build_crt" {
|
||||
source = "./modules/build_crt"
|
||||
}
|
||||
@@ -35,6 +35,14 @@ module "build_local" {
|
||||
source = "./modules/build_local"
|
||||
}
|
||||
|
||||
module "generate_aws_host_tag_vars" {
|
||||
source = "./modules/generate_aws_host_tag_vars"
|
||||
}
|
||||
|
||||
module "iam_setup" {
|
||||
source = "./modules/iam_setup"
|
||||
}
|
||||
|
||||
module "infra" {
|
||||
source = "app.terraform.io/hashicorp-qti/aws-infra/enos"
|
||||
version = ">= 0.3.1"
|
||||
@@ -77,10 +85,6 @@ module "vault" {
|
||||
ssh_aws_keypair = var.aws_ssh_keypair_name
|
||||
}
|
||||
|
||||
module "test_smoke" {
|
||||
source = "./modules/test_smoke"
|
||||
}
|
||||
|
||||
module "test_cli_ui" {
|
||||
source = "./modules/test_cli_ui"
|
||||
}
|
||||
@@ -88,3 +92,7 @@ module "test_cli_ui" {
|
||||
module "test_e2e" {
|
||||
source = "./modules/test_e2e"
|
||||
}
|
||||
|
||||
module "test_smoke" {
|
||||
source = "./modules/test_smoke"
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
scenario "e2e_vault" {
|
||||
scenario "e2e_credential_vault" {
|
||||
terraform_cli = terraform_cli.default
|
||||
terraform = terraform.default
|
||||
providers = [
|
||||
@@ -18,14 +18,11 @@ scenario "e2e_vault" {
|
||||
"local" = "/tmp",
|
||||
"crt" = var.crt_bundle_path == null ? null : abspath(var.crt_bundle_path)
|
||||
}
|
||||
}
|
||||
|
||||
step "check_jq_is_installed" {
|
||||
module = module.binary_finder
|
||||
|
||||
variables {
|
||||
name = "jq"
|
||||
}
|
||||
tags = merge({
|
||||
"Project Name" : var.project_name
|
||||
"Project" : "Enos",
|
||||
"Environment" : "ci"
|
||||
}, var.tags)
|
||||
}
|
||||
|
||||
step "find_azs" {
|
||||
@@ -56,6 +53,7 @@ scenario "e2e_vault" {
|
||||
|
||||
variables {
|
||||
availability_zones = step.find_azs.availability_zones
|
||||
common_tags = local.tags
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +66,7 @@ scenario "e2e_vault" {
|
||||
|
||||
variables {
|
||||
boundary_install_dir = local.boundary_install_dir
|
||||
common_tags = local.tags
|
||||
controller_instance_type = var.controller_instance_type
|
||||
controller_count = var.controller_count
|
||||
db_pass = step.create_db_password.string
|
||||
@@ -0,0 +1,192 @@
|
||||
# This scenario requires access to the boundary team's test AWS account
|
||||
scenario "e2e_host_aws" {
|
||||
terraform_cli = terraform_cli.default
|
||||
terraform = terraform.default
|
||||
providers = [
|
||||
provider.aws.default,
|
||||
provider.enos.default
|
||||
]
|
||||
|
||||
matrix {
|
||||
builder = ["local", "crt"]
|
||||
}
|
||||
|
||||
locals {
|
||||
aws_ssh_private_key_path = abspath(var.aws_ssh_private_key_path)
|
||||
boundary_install_dir = abspath(var.boundary_install_dir)
|
||||
local_boundary_dir = abspath(var.local_boundary_dir)
|
||||
build_path = {
|
||||
"local" = "/tmp",
|
||||
"crt" = var.crt_bundle_path == null ? null : abspath(var.crt_bundle_path)
|
||||
}
|
||||
tags = merge({
|
||||
"Project Name" : var.project_name
|
||||
"Project" : "Enos",
|
||||
"Environment" : "ci"
|
||||
}, var.tags)
|
||||
}
|
||||
|
||||
step "find_azs" {
|
||||
module = module.az_finder
|
||||
|
||||
variables {
|
||||
instance_type = [
|
||||
var.worker_instance_type,
|
||||
var.controller_instance_type
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
step "create_db_password" {
|
||||
module = module.random_stringifier
|
||||
}
|
||||
|
||||
step "build_boundary" {
|
||||
module = matrix.builder == "crt" ? module.build_crt : module.build_local
|
||||
|
||||
variables {
|
||||
path = local.build_path[matrix.builder]
|
||||
}
|
||||
}
|
||||
|
||||
step "create_base_infra" {
|
||||
module = module.infra
|
||||
|
||||
variables {
|
||||
availability_zones = step.find_azs.availability_zones
|
||||
common_tags = local.tags
|
||||
}
|
||||
}
|
||||
|
||||
step "create_boundary_cluster" {
|
||||
module = module.boundary
|
||||
depends_on = [
|
||||
step.create_base_infra,
|
||||
step.build_boundary
|
||||
]
|
||||
|
||||
variables {
|
||||
boundary_install_dir = local.boundary_install_dir
|
||||
common_tags = local.tags
|
||||
controller_instance_type = var.controller_instance_type
|
||||
controller_count = var.controller_count
|
||||
db_pass = step.create_db_password.string
|
||||
kms_key_arn = step.create_base_infra.kms_key_arn
|
||||
local_artifact_path = step.build_boundary.artifact_path
|
||||
ubuntu_ami_id = step.create_base_infra.ami_ids["ubuntu"]["amd64"]
|
||||
vpc_id = step.create_base_infra.vpc_id
|
||||
worker_count = var.worker_count
|
||||
worker_instance_type = var.worker_instance_type
|
||||
}
|
||||
}
|
||||
|
||||
step "create_tag1" {
|
||||
module = module.random_stringifier
|
||||
}
|
||||
|
||||
step "create_tag1_inputs" {
|
||||
module = module.generate_aws_host_tag_vars
|
||||
depends_on = [step.create_tag1]
|
||||
|
||||
variables {
|
||||
tag_name = step.create_tag1.string
|
||||
tag_value = "true"
|
||||
}
|
||||
}
|
||||
|
||||
step "create_targets_with_tag1" {
|
||||
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
|
||||
target_count = 2
|
||||
additional_tags = step.create_tag1_inputs.tag_map
|
||||
}
|
||||
}
|
||||
|
||||
step "create_tag2" {
|
||||
module = module.random_stringifier
|
||||
}
|
||||
|
||||
step "create_tag2_inputs" {
|
||||
module = module.generate_aws_host_tag_vars
|
||||
depends_on = [step.create_tag2]
|
||||
|
||||
variables {
|
||||
tag_name = step.create_tag2.string
|
||||
tag_value = "test"
|
||||
}
|
||||
}
|
||||
|
||||
step "create_targets_with_tag2" {
|
||||
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
|
||||
target_count = 1
|
||||
additional_tags = step.create_tag2_inputs.tag_map
|
||||
}
|
||||
}
|
||||
|
||||
step "create_test_id" {
|
||||
module = module.random_stringifier
|
||||
variables {
|
||||
length = 5
|
||||
}
|
||||
}
|
||||
|
||||
step "iam_setup" {
|
||||
module = module.iam_setup
|
||||
depends_on = [
|
||||
step.create_base_infra,
|
||||
step.create_test_id
|
||||
]
|
||||
|
||||
variables {
|
||||
test_id = step.create_test_id.string
|
||||
test_email = var.test_email
|
||||
}
|
||||
}
|
||||
|
||||
step "run_e2e_test" {
|
||||
module = module.test_e2e
|
||||
depends_on = [
|
||||
step.create_boundary_cluster,
|
||||
step.create_targets_with_tag1,
|
||||
step.create_targets_with_tag2,
|
||||
step.iam_setup
|
||||
]
|
||||
|
||||
variables {
|
||||
test_package = "github.com/hashicorp/boundary/testing/internal/e2e/host/aws"
|
||||
alb_boundary_api_addr = step.create_boundary_cluster.alb_boundary_api_addr
|
||||
auth_method_id = step.create_boundary_cluster.auth_method_id
|
||||
auth_login_name = step.create_boundary_cluster.auth_login_name
|
||||
auth_password = step.create_boundary_cluster.auth_password
|
||||
local_boundary_dir = local.local_boundary_dir
|
||||
aws_ssh_private_key_path = local.aws_ssh_private_key_path
|
||||
target_user = "ubuntu"
|
||||
aws_access_key_id = step.iam_setup.access_key_id
|
||||
aws_secret_access_key = step.iam_setup.secret_access_key
|
||||
aws_host_set_filter1 = step.create_tag1_inputs.tag_string
|
||||
aws_host_set_count1 = 2
|
||||
aws_host_set_ips1 = step.create_targets_with_tag1.target_ips
|
||||
aws_host_set_filter2 = step.create_tag2_inputs.tag_string
|
||||
aws_host_set_count2 = 1
|
||||
}
|
||||
}
|
||||
|
||||
output "test_results" {
|
||||
value = step.run_e2e_test.test_results
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
scenario "e2e_target" {
|
||||
scenario "e2e_host_static" {
|
||||
terraform_cli = terraform_cli.default
|
||||
terraform = terraform.default
|
||||
providers = [
|
||||
@@ -101,7 +101,7 @@ scenario "e2e_target" {
|
||||
]
|
||||
|
||||
variables {
|
||||
test_package = "github.com/hashicorp/boundary/testing/internal/e2e/target"
|
||||
test_package = "github.com/hashicorp/boundary/testing/internal/e2e/host/static"
|
||||
alb_boundary_api_addr = step.create_boundary_cluster.alb_boundary_api_addr
|
||||
auth_method_id = step.create_boundary_cluster.auth_method_id
|
||||
auth_login_name = step.create_boundary_cluster.auth_login_name
|
||||
@@ -109,3 +109,9 @@ variable "vault_instance_type" {
|
||||
type = string
|
||||
default = "t3a.small"
|
||||
}
|
||||
|
||||
variable "test_email" {
|
||||
description = "Email address for setting up AWS IAM user (module: iam_setup)"
|
||||
type = string
|
||||
default = null
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
variable "tag_name" {
|
||||
type = string
|
||||
}
|
||||
variable "tag_value" {
|
||||
type = string
|
||||
}
|
||||
|
||||
locals {
|
||||
tag_map = { "e2e_${var.tag_name}" : var.tag_value }
|
||||
tag_string = "tag:e2e_${var.tag_name}=${var.tag_value}"
|
||||
}
|
||||
|
||||
output "tag_map" {
|
||||
value = local.tag_map
|
||||
}
|
||||
|
||||
output "tag_string" {
|
||||
value = local.tag_string
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
data "aws_caller_identity" "current" {}
|
||||
|
||||
variable "test_id" {}
|
||||
variable "test_email" {}
|
||||
|
||||
locals {
|
||||
# Use the AWS provided email if users are running this, override with variable for CI
|
||||
user_email = var.test_email == null ? split(":", data.aws_caller_identity.current.user_id)[1] : var.test_email
|
||||
}
|
||||
|
||||
resource "aws_iam_user" "boundary" {
|
||||
name = "boundary-e2e-${var.test_id}"
|
||||
tags = { boundary-demo = local.user_email }
|
||||
permissions_boundary = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:policy/BoundaryDemoPermissionsBoundary"
|
||||
}
|
||||
|
||||
resource "aws_iam_user_policy" "boundary" {
|
||||
name = "boundary_e2e_${var.test_id}"
|
||||
user = aws_iam_user.boundary.name
|
||||
policy = jsonencode({
|
||||
"Version" : "2012-10-17",
|
||||
"Statement" : [
|
||||
{
|
||||
"Action" : [
|
||||
"ec2:DescribeInstances"
|
||||
],
|
||||
"Effect" : "Allow",
|
||||
"Resource" : "*"
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
resource "aws_iam_access_key" "boundary" {
|
||||
user = aws_iam_user.boundary.name
|
||||
}
|
||||
|
||||
output "access_key_id" {
|
||||
value = aws_iam_access_key.boundary.id
|
||||
}
|
||||
|
||||
output "secret_access_key" {
|
||||
value = aws_iam_access_key.boundary.secret
|
||||
sensitive = true
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
variable "length" {
|
||||
type = number
|
||||
default = 10
|
||||
}
|
||||
resource "random_string" "string" {
|
||||
length = 10
|
||||
length = var.length
|
||||
lower = true
|
||||
upper = true
|
||||
numeric = true
|
||||
|
||||
@@ -6,6 +6,9 @@ variable "project_name" {}
|
||||
variable "instance_type" {}
|
||||
variable "aws_ssh_keypair_name" {}
|
||||
variable "enos_user" {}
|
||||
variable "additional_tags" {
|
||||
default = {}
|
||||
}
|
||||
|
||||
data "aws_subnets" "infra" {
|
||||
filter {
|
||||
@@ -15,7 +18,7 @@ data "aws_subnets" "infra" {
|
||||
}
|
||||
|
||||
resource "aws_security_group" "boundary_target" {
|
||||
name = "boundary-target-sg"
|
||||
name_prefix = "boundary-target-sg"
|
||||
description = "SSH and boundary Traffic"
|
||||
vpc_id = var.vpc_id
|
||||
|
||||
@@ -47,12 +50,12 @@ resource "aws_instance" "target" {
|
||||
subnet_id = tolist(data.aws_subnets.infra.ids)[count.index % length(data.aws_subnets.infra.ids)]
|
||||
key_name = var.aws_ssh_keypair_name
|
||||
|
||||
tags = {
|
||||
tags = merge(var.additional_tags, {
|
||||
"Name" : "boundary-target-${count.index}",
|
||||
"Type" : "target",
|
||||
"Environment" : var.environment
|
||||
"Enos User" : var.enos_user,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
output "target_ips" {
|
||||
|
||||
@@ -41,6 +41,7 @@ variable "aws_ssh_private_key_path" {
|
||||
variable "target_ips" {
|
||||
description = "List of IP Addresses of created hosts"
|
||||
type = list(string)
|
||||
default = [""]
|
||||
}
|
||||
variable "vault_addr" {
|
||||
description = "URL of Vault instance"
|
||||
@@ -52,10 +53,46 @@ variable "vault_root_token" {
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
variable "aws_access_key_id" {
|
||||
description = "Access Key Id for AWS IAM user used in dynamic host catalogs"
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
variable "aws_secret_access_key" {
|
||||
description = "Secret Access Key for AWS IAM user used in dynamic host catalogs"
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
variable "aws_host_set_filter1" {
|
||||
description = "Filter tag for host set used in dynamic host catalogs"
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
variable "aws_host_set_count1" {
|
||||
description = "Number of hosts in aws_host_set_filter1"
|
||||
type = number
|
||||
default = 0
|
||||
}
|
||||
variable "aws_host_set_ips1" {
|
||||
description = "List of IP addresses in aws_host_set_filter1"
|
||||
type = list(string)
|
||||
default = [""]
|
||||
}
|
||||
variable "aws_host_set_filter2" {
|
||||
description = "Filter tag for host set used in dynamic host catalogs"
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
variable "aws_host_set_count2" {
|
||||
description = "Number of hosts in aws_host_set_filter2"
|
||||
type = number
|
||||
default = 0
|
||||
}
|
||||
|
||||
locals {
|
||||
aws_ssh_private_key_path = abspath(var.aws_ssh_private_key_path)
|
||||
vault_addr = var.vault_addr != "" ? "http://${var.vault_addr}:8200" : ""
|
||||
aws_host_set_ips1 = jsonencode(var.aws_host_set_ips1)
|
||||
}
|
||||
|
||||
resource "enos_local_exec" "run_e2e_test" {
|
||||
@@ -68,7 +105,14 @@ resource "enos_local_exec" "run_e2e_test" {
|
||||
E2E_SSH_USER = var.target_user,
|
||||
E2E_SSH_KEY_PATH = local.aws_ssh_private_key_path,
|
||||
VAULT_ADDR = local.vault_addr,
|
||||
VAULT_TOKEN = var.vault_root_token
|
||||
VAULT_TOKEN = var.vault_root_token,
|
||||
E2E_AWS_ACCESS_KEY_ID = var.aws_access_key_id,
|
||||
E2E_AWS_SECRET_ACCESS_KEY = var.aws_secret_access_key,
|
||||
E2E_AWS_HOST_SET_FILTER1 = var.aws_host_set_filter1,
|
||||
E2E_AWS_HOST_SET_COUNT1 = var.aws_host_set_count1,
|
||||
E2E_AWS_HOST_SET_IPS1 = local.aws_host_set_ips1,
|
||||
E2E_AWS_HOST_SET_FILTER2 = var.aws_host_set_filter2,
|
||||
E2E_AWS_HOST_SET_COUNT2 = var.aws_host_set_count2
|
||||
}
|
||||
|
||||
inline = ["PATH=\"${var.local_boundary_dir}:$PATH\" go test -v ${var.test_package}"]
|
||||
|
||||
Reference in new issue
Block a user