From 06788b5bf81fd6d291537ae24a8955ab49563b9e Mon Sep 17 00:00:00 2001 From: MOZGIII Date: Fri, 27 Mar 2020 00:27:32 +0300 Subject: [PATCH 1/6] Correct paths at terraform topology configs --- terraform/aws_tcp_bi_topology/main.tf | 8 ++++---- terraform/aws_uni_topology/main.tf | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/terraform/aws_tcp_bi_topology/main.tf b/terraform/aws_tcp_bi_topology/main.tf index 5afec72..40501dc 100644 --- a/terraform/aws_tcp_bi_topology/main.tf +++ b/terraform/aws_tcp_bi_topology/main.tf @@ -11,7 +11,7 @@ locals { } module "vpc" { - source = "../../../terraform/aws_vpc" + source = "../aws_vpc" providers = { aws = aws @@ -74,7 +74,7 @@ resource "aws_security_group" "consumer" { } module "aws_instance_profile" { - source = "../../../terraform/aws_instance_profile" + source = "../aws_instance_profile" providers = { aws = aws @@ -86,7 +86,7 @@ module "aws_instance_profile" { } module "aws_instance_subject" { - source = "../../../terraform/aws_instance" + source = "../aws_instance" providers = { aws = aws @@ -105,7 +105,7 @@ module "aws_instance_subject" { } module "aws_instance_consumer" { - source = "../../../terraform/aws_instance" + source = "../aws_instance" providers = { aws = aws diff --git a/terraform/aws_uni_topology/main.tf b/terraform/aws_uni_topology/main.tf index 81c187d..912d1b2 100644 --- a/terraform/aws_uni_topology/main.tf +++ b/terraform/aws_uni_topology/main.tf @@ -11,7 +11,7 @@ locals { } module "vpc" { - source = "../../../terraform/aws_vpc" + source = "../aws_vpc" providers = { aws = aws @@ -24,7 +24,7 @@ module "vpc" { } module "aws_instance_profile" { - source = "../../../terraform/aws_instance_profile" + source = "../aws_instance_profile" providers = { aws = aws @@ -36,7 +36,7 @@ module "aws_instance_profile" { } module "aws_instance_subject" { - source = "../../../terraform/aws_instance" + source = "../aws_instance" providers = { aws = aws From 005886f5aa85e5f382f18734e01b89e2ab2e9db3 Mon Sep 17 00:00:00 2001 From: MOZGIII Date: Wed, 1 Apr 2020 23:30:29 +0300 Subject: [PATCH 2/6] Use the test configuration at aws_instance_profile to avoid collisions --- terraform/aws_instance_profile/main.tf | 8 ++++---- terraform/aws_instance_profile/variables.tf | 8 ++++++++ terraform/aws_tcp_bi_topology/main.tf | 1 + terraform/aws_tcp_tri_topology/main.tf | 1 + terraform/aws_uni_topology/main.tf | 1 + 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/terraform/aws_instance_profile/main.tf b/terraform/aws_instance_profile/main.tf index 2ff5035..1e7ffdf 100644 --- a/terraform/aws_instance_profile/main.tf +++ b/terraform/aws_instance_profile/main.tf @@ -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 } diff --git a/terraform/aws_instance_profile/variables.tf b/terraform/aws_instance_profile/variables.tf index 283a51f..49a2b7c 100644 --- a/terraform/aws_instance_profile/variables.tf +++ b/terraform/aws_instance_profile/variables.tf @@ -1,3 +1,11 @@ +variable "test_configuration" { + type = string + + description = < Date: Thu, 2 Apr 2020 00:01:07 +0300 Subject: [PATCH 3/6] Allow terraform interactivity if requested Use this at your own risk! It's counter-intuitive, but local references to the remote terraform state are currently shared accross user_id and test_configuration, and you should not migrate them! Instead, clear local state when switching the configuration or user id. It'll be addressed in the future. --- bin/global-bootstrap | 8 ++++++-- bin/test | 4 ++-- lib/vector-test-harness/terraform.sh | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/bin/global-bootstrap b/bin/global-bootstrap index 0657a2d..c8cf486 100755 --- a/bin/global-bootstrap +++ b/bin/global-bootstrap @@ -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\"]" diff --git a/bin/test b/bin/test index 3a557c6..a909d7d 100755 --- a/bin/test +++ b/bin/test @@ -202,7 +202,7 @@ if [ "$BOOTSTRAP" == 'true' ] && [ "$SKIP_TERRAFORM" != 'true' ]; then cd terraform 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" \ @@ -211,7 +211,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" \ diff --git a/lib/vector-test-harness/terraform.sh b/lib/vector-test-harness/terraform.sh index a6cf788..009d2f7 100644 --- a/lib/vector-test-harness/terraform.sh +++ b/lib/vector-test-harness/terraform.sh @@ -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+=( @@ -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 } From 8e6e012b1412f18ee853f29f16f5e9166e8072fe Mon Sep 17 00:00:00 2001 From: MOZGIII Date: Thu, 2 Apr 2020 00:03:16 +0300 Subject: [PATCH 4/6] Rename big-vms to bin_vms - test configuration can't contain dashes --- .../configurations/{big-vms => big_vms}/ansible.yml | 0 .../configurations/{big-vms => big_vms}/terraform.tfvars | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename cases/tcp_to_tcp_performance/configurations/{big-vms => big_vms}/ansible.yml (100%) rename cases/tcp_to_tcp_performance/configurations/{big-vms => big_vms}/terraform.tfvars (100%) diff --git a/cases/tcp_to_tcp_performance/configurations/big-vms/ansible.yml b/cases/tcp_to_tcp_performance/configurations/big_vms/ansible.yml similarity index 100% rename from cases/tcp_to_tcp_performance/configurations/big-vms/ansible.yml rename to cases/tcp_to_tcp_performance/configurations/big_vms/ansible.yml diff --git a/cases/tcp_to_tcp_performance/configurations/big-vms/terraform.tfvars b/cases/tcp_to_tcp_performance/configurations/big_vms/terraform.tfvars similarity index 100% rename from cases/tcp_to_tcp_performance/configurations/big-vms/terraform.tfvars rename to cases/tcp_to_tcp_performance/configurations/big_vms/terraform.tfvars From 1089e8aeb425185c150122f3ab1eb03f6975f2a6 Mon Sep 17 00:00:00 2001 From: MOZGIII Date: Thu, 2 Apr 2020 00:10:16 +0300 Subject: [PATCH 5/6] Add early input validation to avoid issues with dashes later --- bin/test | 6 ++++++ lib/vector-test-harness/misc.sh | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/bin/test b/bin/test index a909d7d..a621bb2 100755 --- a/bin/test +++ b/bin/test @@ -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" diff --git a/lib/vector-test-harness/misc.sh b/lib/vector-test-harness/misc.sh index 4aacb7e..12b4e75 100644 --- a/lib/vector-test-harness/misc.sh +++ b/lib/vector-test-harness/misc.sh @@ -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 +} From 6f168aa93d8be14de89a30ec1487ae28ea20c6e7 Mon Sep 17 00:00:00 2001 From: MOZGIII Date: Thu, 2 Apr 2020 00:34:41 +0300 Subject: [PATCH 6/6] Make terraform use a custom data dir per-test configuration and user id --- bin/test | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/test b/bin/test index a621bb2..878cc0f 100755 --- a/bin/test +++ b/bin/test @@ -195,7 +195,6 @@ prepare_ansible_extra_args_array true # Execute # -export TF_IN_AUTOMATION=true cd "$TEST_CASE_DIR" # @@ -207,6 +206,9 @@ 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 \ "${TERRAFORM_COMMON_EXTRA_ARGS[@]}" \ -backend-config="bucket=vector-test-harness-state" \