Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions bin/global-bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ export TF_IN_AUTOMATION=true

cd global

terraform init -input=false "${TERRAFORM_INIT_EXTRA_ARGS[@]}"
terraform init \
"${TERRAFORM_COMMON_EXTRA_ARGS[@]}" \
"${TERRAFORM_INIT_EXTRA_ARGS[@]}"

terraform apply -input=false -auto-approve \
terraform apply \
"${TERRAFORM_COMMON_EXTRA_ARGS[@]}" \
-auto-approve \
-var results_s3_bucket_name="$TEST_RESULTS_S3_BUCKET_NAME" \
-var test_harness_aws_account_ids="[\"$TEST_HARNESS_AWS_ACCOUNT_ID\"]"
14 changes: 11 additions & 3 deletions bin/test
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,20 @@ if [ -z "$TEST_CONFIGURATION" ]; then
fail_arg_invalid "Error: you must supply a test configuration via the -c flag:"
fi

ensure_no_dashes "$TEST_CONFIGURATION" "Test configuration can't contain dashes"

if [ -z "$TEST_NAME" ]; then
fail_arg_invalid "Error: you must supply a test name via the -t flag:"
fi

ensure_no_dashes "$TEST_NAME" "Test name can't contain dashes"

if [ -z "$TEST_USER_ID" ]; then
fail_arg_invalid "Error: you must supply a user ID via the -u flag or VECTOR_TEST_USER_ID env var:"
fi

ensure_no_dashes "$TEST_USER_ID" "User ID can't contain dashes"

TEST_CASE_DIR="cases/$TEST_NAME"
if [[ ! -d "$TEST_CASE_DIR" ]]; then
fail_arg_invalid "Error: test $TEST_NAME does not exist"
Expand Down Expand Up @@ -189,7 +195,6 @@ prepare_ansible_extra_args_array true
# Execute
#

export TF_IN_AUTOMATION=true
cd "$TEST_CASE_DIR"

#
Expand All @@ -201,8 +206,11 @@ if [ "$BOOTSTRAP" == 'true' ] && [ "$SKIP_TERRAFORM" != 'true' ]; then

cd terraform

export TF_IN_AUTOMATION=true
export TF_DATA_DIR=".terraform/$TEST_CONFIGURATION/$TEST_USER_ID"

terraform init \
-input=false \
"${TERRAFORM_COMMON_EXTRA_ARGS[@]}" \
-backend-config="bucket=vector-test-harness-state" \
-backend-config="region=us-east-1" \
-backend-config="encrypt=true" \
Expand All @@ -211,7 +219,7 @@ if [ "$BOOTSTRAP" == 'true' ] && [ "$SKIP_TERRAFORM" != 'true' ]; then
"${TERRAFORM_INIT_EXTRA_ARGS[@]}"

terraform apply \
-input=false \
"${TERRAFORM_COMMON_EXTRA_ARGS[@]}" \
-auto-approve \
-var pub_key="$TEST_SSH_PUBLIC_KEY" \
-var test_name="$TEST_NAME" \
Expand Down
9 changes: 9 additions & 0 deletions lib/vector-test-harness/misc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,12 @@ spin() {
done
done
}

ensure_no_dashes() {
local STRING="$1"
local ERROR="$2"
if [[ "$STRING" == *"-"* ]]; then
error "Error: $ERROR"
exit 1
fi
}
14 changes: 14 additions & 0 deletions lib/vector-test-harness/terraform.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ prepare_terraform_params() {
local VERBOSE="${1:-"false"}"

TERRAFORM_INIT_EXTRA_ARGS=()
TERRAFORM_COMMON_EXTRA_ARGS=()

if [[ -n "${TF_PLUGIN_DIR:-""}" ]]; then
TERRAFORM_INIT_EXTRA_ARGS+=(
Expand All @@ -15,4 +16,17 @@ prepare_terraform_params() {
echo "Terraform plugins dir: $TF_PLUGIN_DIR"
fi
fi

if [[ "${TF_INTERACTIVE:-""}" == "true" ]]; then
TERRAFORM_COMMON_EXTRA_ARGS+=(
"-input=true"
)
if [[ "$VERBOSE" != "false" ]]; then
echo "Terraform will accept interactive input"
fi
else
TERRAFORM_COMMON_EXTRA_ARGS+=(
"-input=false"
)
fi
}
8 changes: 4 additions & 4 deletions terraform/aws_instance_profile/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ data "aws_arn" "results_s3_bucket" {
}

resource "aws_iam_instance_profile" "default" {
name = "vector-test-${var.user_id}-${var.test_name}"
path = "/vector-test/${var.user_id}/${var.test_name}/"
name = "vector-test-${var.user_id}-${var.test_configuration}-${var.test_name}"
path = "/vector-test/${var.user_id}/${var.test_configuration}/${var.test_name}/"
role = aws_iam_role.default.name
}

resource "aws_iam_role" "default" {
name = "vector-test-${var.user_id}-${var.test_name}"
path = "/vector-test/${var.user_id}/${var.test_name}/"
name = "vector-test-${var.user_id}-${var.test_configuration}-${var.test_name}"
path = "/vector-test/${var.user_id}/${var.test_configuration}/${var.test_name}/"
assume_role_policy = data.aws_iam_policy_document.allow_ec2_assume.json
}

Expand Down
8 changes: 8 additions & 0 deletions terraform/aws_instance_profile/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
variable "test_configuration" {
type = string

description = <<EOF
The configuration name of the current test.
EOF
}

variable "test_name" {
type = string

Expand Down
9 changes: 5 additions & 4 deletions terraform/aws_tcp_bi_topology/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ locals {
}

module "vpc" {
source = "../../../terraform/aws_vpc"
source = "../aws_vpc"

providers = {
aws = aws
Expand Down Expand Up @@ -74,19 +74,20 @@ resource "aws_security_group" "consumer" {
}

module "aws_instance_profile" {
source = "../../../terraform/aws_instance_profile"
source = "../aws_instance_profile"

providers = {
aws = aws
}

test_configuration = local.test_configuration
test_name = local.test_name
user_id = local.user_id
results_s3_bucket_name = local.results_s3_bucket_name
}

module "aws_instance_subject" {
source = "../../../terraform/aws_instance"
source = "../aws_instance"

providers = {
aws = aws
Expand All @@ -105,7 +106,7 @@ module "aws_instance_subject" {
}

module "aws_instance_consumer" {
source = "../../../terraform/aws_instance"
source = "../aws_instance"

providers = {
aws = aws
Expand Down
1 change: 1 addition & 0 deletions terraform/aws_tcp_tri_topology/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ module "aws_instance_profile" {
aws = aws
}

test_configuration = local.test_configuration
test_name = local.test_name
user_id = local.user_id
results_s3_bucket_name = local.results_s3_bucket_name
Expand Down
7 changes: 4 additions & 3 deletions terraform/aws_uni_topology/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ locals {
}

module "vpc" {
source = "../../../terraform/aws_vpc"
source = "../aws_vpc"

providers = {
aws = aws
Expand All @@ -24,19 +24,20 @@ module "vpc" {
}

module "aws_instance_profile" {
source = "../../../terraform/aws_instance_profile"
source = "../aws_instance_profile"

providers = {
aws = aws
}

test_configuration = local.test_configuration
test_name = local.test_name
user_id = local.user_id
results_s3_bucket_name = local.results_s3_bucket_name
}

module "aws_instance_subject" {
source = "../../../terraform/aws_instance"
source = "../aws_instance"

providers = {
aws = aws
Expand Down