From 7eb4f205f18f9a5ecf85b6d937d92e6c7588b8cb Mon Sep 17 00:00:00 2001 From: Edoardo Tenani Date: Fri, 13 Dec 2024 19:14:20 +0100 Subject: [PATCH] add target to terraform code We want to run these tests against multiple environments, which requires selecting the appropriate API endpoint --- .github/workflows/functional-tests.yml | 2 +- .../TestUpgrade_8_15_4_to_8_16_0/terraform.tf | 9 ++++++++- .../TestUpgrade_8_15_4_to_8_16_0/vars.tf | 9 +++++++++ functionaltests/main_test.go | 13 +++++-------- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/.github/workflows/functional-tests.yml b/.github/workflows/functional-tests.yml index 5194f02376d..dab22aa7170 100644 --- a/.github/workflows/functional-tests.yml +++ b/.github/workflows/functional-tests.yml @@ -34,7 +34,7 @@ jobs: secrets: |- EC_API_KEY:elastic-observability/elastic-cloud-observability-team-${{ matrix.environment }}-api-key - - run: cd functionaltests && go test -v ./ + - run: cd functionaltests && go test -v -target "${{ matrix.environment }}" ./ notify: if: always() diff --git a/functionaltests/TestUpgrade_8_15_4_to_8_16_0/terraform.tf b/functionaltests/TestUpgrade_8_15_4_to_8_16_0/terraform.tf index 41454377011..17c990dd604 100644 --- a/functionaltests/TestUpgrade_8_15_4_to_8_16_0/terraform.tf +++ b/functionaltests/TestUpgrade_8_15_4_to_8_16_0/terraform.tf @@ -9,6 +9,13 @@ terraform { } } +locals { + api_endpoints = { + qa = "https://public-api.qa.cld.elstc.co" + production = "https://api.elastic-cloud.com" + } +} + provider "ec" { - endpoint = "https://public-api.qa.cld.elstc.co" + endpoint = local.api_endpoints[var.ec_target] } diff --git a/functionaltests/TestUpgrade_8_15_4_to_8_16_0/vars.tf b/functionaltests/TestUpgrade_8_15_4_to_8_16_0/vars.tf index b0e729b7f2b..78489b9eb41 100644 --- a/functionaltests/TestUpgrade_8_15_4_to_8_16_0/vars.tf +++ b/functionaltests/TestUpgrade_8_15_4_to_8_16_0/vars.tf @@ -1,3 +1,12 @@ +variable "ec_target" { + type = string + description = "The Elastic Cloud environment to target" + validation { + condition = contains(["qa", "production", "item3"], var.ec_target) + error_message = "Valid values are (qa, production)." + } +} + variable "name" { type = string description = "The deployment name" diff --git a/functionaltests/main_test.go b/functionaltests/main_test.go index 28435835364..61cc7cd26a9 100644 --- a/functionaltests/main_test.go +++ b/functionaltests/main_test.go @@ -37,14 +37,10 @@ import ( ) var cleanupOnFailure *bool = flag.Bool("cleanup-on-failure", true, "Whether to run cleanup even if the test failed.") +var target *string = flag.String("target", "production", "The target environment where to run tests againts.") const testRegion = "aws-eu-west-1" -const ( - ecAPIEndpoint = "api.elastic-cloud.com" - ecAPIEndpointQA = "https://public-api.qa.cld.elstc.co" -) - func TestUpgrade_8_15_4_to_8_16_0(t *testing.T) { require.NoError(t, ecAPICheck(t)) @@ -54,15 +50,16 @@ func TestUpgrade_8_15_4_to_8_16_0(t *testing.T) { t.Log("creating deploment with terraform") tf, err := terraform.New(t, t.Name()) require.NoError(t, err) + ecTarget := terraform.Var("ec_target", *target) version := terraform.Var("stack_version", "8.15.4") name := terraform.Var("name", t.Name()) - require.NoError(t, tf.Apply(ctx, version, name)) + require.NoError(t, tf.Apply(ctx, ecTarget, version, name)) t.Cleanup(func() { // cleanup if !t.Failed() || (t.Failed() && *cleanupOnFailure) { t.Log("cleanup terraform resources") - require.NoError(t, tf.Destroy(ctx, name, version)) + require.NoError(t, tf.Destroy(ctx, ecTarget, name, version)) } else { t.Log("test failed and cleanup-on-failure is false, skipping cleanup") } @@ -122,7 +119,7 @@ func TestUpgrade_8_15_4_to_8_16_0(t *testing.T) { // Upgrade to 8.16.0 // FIXME: the update failed because it took more than 10m t.Log("upgrade to 8.16.0") - require.NoError(t, tf.Apply(ctx, name, terraform.Var("stack_version", "8.16.0"))) + require.NoError(t, tf.Apply(ctx, ecTarget, name, terraform.Var("stack_version", "8.16.0"))) // check data newCount, err := ac.ApmDocCount(ctx)