Skip to content

Commit

Permalink
add target to terraform code
Browse files Browse the repository at this point in the history
We want to run these tests against multiple environments,
which requires selecting the appropriate API endpoint
  • Loading branch information
endorama committed Dec 13, 2024
1 parent e4ebced commit 7eb4f20
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/functional-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 8 additions & 1 deletion functionaltests/TestUpgrade_8_15_4_to_8_16_0/terraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
9 changes: 9 additions & 0 deletions functionaltests/TestUpgrade_8_15_4_to_8_16_0/vars.tf
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
13 changes: 5 additions & 8 deletions functionaltests/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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")
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7eb4f20

Please sign in to comment.