Skip to content

Commit

Permalink
chore: Clean up environment variables in tests and on CI (#2543)
Browse files Browse the repository at this point in the history
Before fixing #2294 and #2242 we need to have a clean CI env. After this
PR it should be possible to completely remove following environment
variables from the secrets:
- AWS_EXTERNAL_BUCKET_URL (it has TEST_SF_TF_AWS_EXTERNAL_BUCKET_URL
replacement)
- AWS_EXTERNAL_KEY_ID (it has TEST_SF_TF_AWS_EXTERNAL_KEY_ID
replacement)
- AWS_EXTERNAL_ROLE_ARN (it has TEST_SF_TF_AWS_EXTERNAL_ROLE_ARN
replacement)
- AWS_EXTERNAL_SECRET_KEY (it has TEST_SF_TF_AWS_EXTERNAL_SECRET_KEY
replacement)
- AZURE_EXTERNAL_BUCKET_URL (it has TEST_SF_TF_AZURE_EXTERNAL_BUCKET_URL
replacement)
- AZURE_EXTERNAL_SAS_TOKEN (it has TEST_SF_TF_AZURE_EXTERNAL_SAS_TOKEN
replacement)
- AZURE_EXTERNAL_TENANT_ID (it has TEST_SF_TF_AZURE_EXTERNAL_TENANT_ID
replacement)
- GCS_EXTERNAL_BUCKET_URL (it has TEST_SF_TF_GCS_EXTERNAL_BUCKET_URL
replacement)
- SKIP_EMAIL_INTEGRATION_TESTS (not used)
- SKIP_EXTERNAL_TABLE_TEST (not used anymore)
- SKIP_NOTIFICATION_INTEGRATION_TESTS (not used)
- SKIP_STREAM_TEST (not used anymore)
- SNOWFLAKE_ACCOUNT (we use the config now, this shouldn't be needed)
- SNOWFLAKE_ACCOUNT_SECOND (not used anymore)
- SNOWFLAKE_ACCOUNT_THIRD (not used anymore)
- SNOWFLAKE_PASSWORD (we use the config now, this shouldn't be needed)
- SNOWFLAKE_ROLE (we use the config now, this shouldn't be needed)
- SNOWFLAKE_USER (we use the config now, this shouldn't be needed)

There are three more that should be removed but they should be
approached more carefully:
- SNOWFLAKE_WAREHOUSE (we do not have it in our config, so it is taken
from env; test what happens without setting a warehouse by running the
tests locally with the config similar to the CI one)
- SNOWFLAKE_PORT (we do not have this in our config, let's check if the
tests will work without this - they should not fail)
- SNOWFLAKE_PROTOCOL (we do not have this in our config, there is a
default, it should be fine without it)
  • Loading branch information
sfc-gh-asawicki authored Feb 23, 2024
1 parent b379565 commit 9a10cb1
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 29 deletions.
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
export SKIP_EMAIL_INTEGRATION_TESTS=true
export SKIP_NOTIFICATION_INTEGRATION_TESTS=true
export SKIP_SAML_INTEGRATION_TESTS=true
export SKIP_STREAM_TEST=true
export SKIP_MANAGED_ACCOUNT_INT_TEST=true
export SKIP_MANAGED_ACCOUNT_TEST=true
export BASE_BINARY_NAME=terraform-provider-snowflake
Expand Down
5 changes: 0 additions & 5 deletions pkg/datasources/external_tables_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package datasources_test

import (
"fmt"
"os"
"strings"
"testing"

Expand All @@ -11,10 +10,6 @@ import (
)

func TestAcc_ExternalTables(t *testing.T) {
if _, ok := os.LookupEnv("SKIP_EXTERNAL_TABLE_TESTS"); ok {
t.Skip("Skipping TestAcc_ExternalTables")
}

databaseName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
schemaName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
stageName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
Expand Down
9 changes: 4 additions & 5 deletions pkg/resources/external_table_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,10 @@ func TestAcc_ExternalTable_DeltaLake(t *testing.T) {
}

func externalTableTestEnvs() (bool, string, string, string) {
shouldSkip := os.Getenv("SKIP_EXTERNAL_TABLE_TEST")
awsBucketURL := os.Getenv("AWS_EXTERNAL_BUCKET_URL")
awsKeyId := os.Getenv("AWS_EXTERNAL_KEY_ID")
awsSecretKey := os.Getenv("AWS_EXTERNAL_SECRET_KEY")
return shouldSkip != "" || awsBucketURL == "" || awsKeyId == "" || awsSecretKey == "", awsBucketURL, awsKeyId, awsSecretKey
awsBucketURL := os.Getenv("TEST_SF_TF_AWS_EXTERNAL_BUCKET_URL")
awsKeyId := os.Getenv("TEST_SF_TF_AWS_EXTERNAL_KEY_ID")
awsSecretKey := os.Getenv("TEST_SF_TF_AWS_EXTERNAL_SECRET_KEY")
return awsBucketURL == "" || awsKeyId == "" || awsSecretKey == "", awsBucketURL, awsKeyId, awsSecretKey
}

func externalTableContainsData(name string, contains func(rows []map[string]*any) bool) func(state *terraform.State) error {
Expand Down
15 changes: 6 additions & 9 deletions pkg/resources/share_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,23 @@ package resources_test

import (
"fmt"
"os"
"strings"
"testing"

acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance"

"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

func TestAcc_Share(t *testing.T) {
t.Skip("second and third account must be set for Share acceptance tests")
var account2 string
var account3 string

shareComment := "Created by a Terraform acceptance test"
name := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
account2 := os.Getenv("SNOWFLAKE_ACCOUNT_SECOND")
if account2 == "" {
t.Skip("SNOWFLAKE_ACCOUNT_SECOND must be set for Share acceptance tests")
}
account3 := os.Getenv("SNOWFLAKE_ACCOUNT_THIRD")
if account3 == "" {
t.Skip("SNOWFLAKE_ACCOUNT_THIRD must be set for Share acceptance tests")
}

resource.ParallelTest(t, resource.TestCase{
Providers: acc.TestAccProviders(),
PreCheck: func() { acc.TestAccPreCheck(t) },
Expand Down
13 changes: 6 additions & 7 deletions pkg/resources/stream_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,16 @@ func TestAcc_StreamCreateOnStage(t *testing.T) {
}

func TestAcc_Stream(t *testing.T) {
env := os.Getenv("SKIP_STREAM_TEST")
if env != "" {
t.Skip("Skipping TestAcc_Stream")
}
// Current error is User: <redacted> is not authorized to perform: sts:AssumeRole on resource: <redacted> duration 1.162414333s args {}] ()
t.Skip("Skipping TestAcc_Stream")

accName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
accNameExternalTable := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
bucketURL := os.Getenv("AWS_EXTERNAL_BUCKET_URL")
bucketURL := os.Getenv("TEST_SF_TF_AWS_EXTERNAL_BUCKET_URL")
if bucketURL == "" {
t.Skip("Skipping TestAcc_ExternalTable")
}
roleName := os.Getenv("AWS_EXTERNAL_ROLE_NAME")
roleName := os.Getenv("TEST_SF_TF_AWS_EXTERNAL_ROLE_ARN")
if roleName == "" {
t.Skip("Skipping TestAcc_ExternalTable")
}
Expand Down Expand Up @@ -230,7 +229,7 @@ resource "snowflake_stage" "test" {
}
resource "snowflake_storage_integration" "external_table_stream_integration" {
name = "%v"
storage_allowed_locations = [%s]
storage_allowed_locations = ["%s"]
storage_provider = "S3"
storage_aws_role_arn = "%s"
}
Expand Down

0 comments on commit 9a10cb1

Please sign in to comment.