From d7ed4b0605accf15ba3f2a42f3578bf71e11e2d5 Mon Sep 17 00:00:00 2001 From: Kristin Laemmert Date: Wed, 25 Sep 2019 14:55:26 -0400 Subject: [PATCH 1/4] tools/terraform-bundle: update e2e tests with current tf and provider versions The terraform version was hard-coded to 0.10.2, and the provider versions supported the older provider protocol version 4. --- .../terraform-bundle/e2etest/package_test.go | 37 ++++++++++--------- .../testdata/empty/terraform-bundle.hcl | 2 +- .../many-providers/terraform-bundle.hcl | 10 ++--- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/tools/terraform-bundle/e2etest/package_test.go b/tools/terraform-bundle/e2etest/package_test.go index fa920cabf..771f4acef 100644 --- a/tools/terraform-bundle/e2etest/package_test.go +++ b/tools/terraform-bundle/e2etest/package_test.go @@ -31,10 +31,10 @@ func TestPackage_empty(t *testing.T) { t.Errorf("unexpected stderr output:\n%s", stderr) } - if !strings.Contains(stdout, "Fetching Terraform 0.10.1 core package...") { + if !strings.Contains(stdout, "Fetching Terraform 0.12.0 core package...") { t.Errorf("success message is missing from output:\n%s", stdout) } - if !strings.Contains(stdout, "Creating terraform_0.10.1-bundle") { + if !strings.Contains(stdout, "Creating terraform_0.12.0-bundle") { t.Errorf("success message is missing from output:\n%s", stdout) } if !strings.Contains(stdout, "All done!") { @@ -65,36 +65,37 @@ func TestPackage_manyProviders(t *testing.T) { t.Errorf("unexpected stderr output:\n%s", stderr) } - if !strings.Contains(stdout, "Checking for available provider plugins on ") { - t.Errorf("success message is missing from output:\n%s", stdout) - } - // Here we have to check each provider separately // because it's internally held in a map (i.e. not guaranteed order) - if !strings.Contains(stdout, `- Resolving "aws" provider (~> 0.1)... -- Downloading plugin for provider "aws" (0.1.4)...`) { + if !strings.Contains(stdout, `- Resolving "aws" provider (~> 2.26.0)... +- Checking for provider plugin on https://releases.hashicorp.com... +- Downloading plugin for provider "aws" (hashicorp/aws) 2.26.0...`) { t.Errorf("success message is missing from output:\n%s", stdout) } - if !strings.Contains(stdout, `- Resolving "kubernetes" provider (0.1.0)... -- Downloading plugin for provider "kubernetes" (0.1.0)... -- Resolving "kubernetes" provider (0.1.1)... -- Downloading plugin for provider "kubernetes" (0.1.1)... -- Resolving "kubernetes" provider (0.1.2)... -- Downloading plugin for provider "kubernetes" (0.1.2)...`) { + if !strings.Contains(stdout, `- Resolving "kubernetes" provider (1.8.0)... +- Checking for provider plugin on https://releases.hashicorp.com... +- Downloading plugin for provider "kubernetes" (hashicorp/kubernetes) 1.8.0... +- Resolving "kubernetes" provider (1.8.1)... +- Checking for provider plugin on https://releases.hashicorp.com... +- Downloading plugin for provider "kubernetes" (hashicorp/kubernetes) 1.8.1... +- Resolving "kubernetes" provider (1.9.0)... +- Checking for provider plugin on https://releases.hashicorp.com... +- Downloading plugin for provider "kubernetes" (hashicorp/kubernetes) 1.9.0...`) { t.Errorf("success message is missing from output:\n%s", stdout) } - if !strings.Contains(stdout, `- Resolving "null" provider (0.1.0)... -- Downloading plugin for provider "null" (0.1.0)...`) { + if !strings.Contains(stdout, `- Resolving "null" provider (2.1.0)... +- Checking for provider plugin on https://releases.hashicorp.com... +- Downloading plugin for provider "null" (hashicorp/null) 2.1.0...`) { t.Errorf("success message is missing from output:\n%s", stdout) } - if !strings.Contains(stdout, "Fetching Terraform 0.10.1 core package...") { + if !strings.Contains(stdout, "Fetching Terraform 0.12.0 core package...") { t.Errorf("success message is missing from output:\n%s", stdout) } - if !strings.Contains(stdout, "Creating terraform_0.10.1-bundle") { + if !strings.Contains(stdout, "Creating terraform_0.12.0-bundle") { t.Errorf("success message is missing from output:\n%s", stdout) } if !strings.Contains(stdout, "All done!") { diff --git a/tools/terraform-bundle/e2etest/testdata/empty/terraform-bundle.hcl b/tools/terraform-bundle/e2etest/testdata/empty/terraform-bundle.hcl index 5350cab4a..328017f8a 100644 --- a/tools/terraform-bundle/e2etest/testdata/empty/terraform-bundle.hcl +++ b/tools/terraform-bundle/e2etest/testdata/empty/terraform-bundle.hcl @@ -1,3 +1,3 @@ terraform { - version = "0.10.1" + version = "0.12.0" } diff --git a/tools/terraform-bundle/e2etest/testdata/many-providers/terraform-bundle.hcl b/tools/terraform-bundle/e2etest/testdata/many-providers/terraform-bundle.hcl index 05ddc8b5f..edc77794d 100644 --- a/tools/terraform-bundle/e2etest/testdata/many-providers/terraform-bundle.hcl +++ b/tools/terraform-bundle/e2etest/testdata/many-providers/terraform-bundle.hcl @@ -1,9 +1,9 @@ terraform { - version = "0.10.1" + version = "0.12.0" } providers { - aws = ["~> 0.1"] - kubernetes = ["0.1.0", "0.1.1", "0.1.2"] - null = ["0.1.0"] -} \ No newline at end of file + aws = ["~> 2.26.0"] + kubernetes = ["1.8.0", "1.8.1", "1.9.0"] + null = ["2.1.0"] +} From 69b6791ef17f75bc2f5eb997097cb2452f857a2c Mon Sep 17 00:00:00 2001 From: Kristin Laemmert Date: Wed, 25 Sep 2019 16:27:17 -0400 Subject: [PATCH 2/4] internal/initwd: fix issues with tests and symlinks filepath.EvalSymlinks is our friend! The code already does this, the tests needed to be updated to do the same. --- internal/initwd/from_module_test.go | 6 +++++- internal/initwd/module_install_test.go | 13 +++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/internal/initwd/from_module_test.go b/internal/initwd/from_module_test.go index 480ead680..b467552b5 100644 --- a/internal/initwd/from_module_test.go +++ b/internal/initwd/from_module_test.go @@ -19,7 +19,11 @@ func TestDirFromModule_registry(t *testing.T) { } fixtureDir := filepath.Clean("testdata/empty") - dir, done := tempChdir(t, fixtureDir) + tmpDir, done := tempChdir(t, fixtureDir) + dir, err := filepath.EvalSymlinks(tmpDir) + if err != nil { + t.Error(err) + } modsDir := filepath.Join(dir, ".terraform/modules") defer done() diff --git a/internal/initwd/module_install_test.go b/internal/initwd/module_install_test.go index 27a82aef7..786f84400 100644 --- a/internal/initwd/module_install_test.go +++ b/internal/initwd/module_install_test.go @@ -232,7 +232,12 @@ func TestLoaderInstallModules_registry(t *testing.T) { } fixtureDir := filepath.Clean("testdata/registry-modules") - dir, done := tempChdir(t, fixtureDir) + tmpDir, done := tempChdir(t, fixtureDir) + dir, err := filepath.EvalSymlinks(tmpDir) + if err != nil { + t.Error(err) + } + defer done() hooks := &testInstallHooks{} @@ -359,7 +364,11 @@ func TestLoaderInstallModules_goGetter(t *testing.T) { } fixtureDir := filepath.Clean("testdata/go-getter-modules") - dir, done := tempChdir(t, fixtureDir) + tmpDir, done := tempChdir(t, fixtureDir) + dir, err := filepath.EvalSymlinks(tmpDir) + if err != nil { + t.Error(err) + } defer done() hooks := &testInstallHooks{} From 5300f85a796fbc5a492428a905e3900a5965ee87 Mon Sep 17 00:00:00 2001 From: Kristin Laemmert Date: Thu, 26 Sep 2019 10:08:29 -0400 Subject: [PATCH 3/4] backend/manta: fix panic when insecure_skip_tls_verify was not set The DefaultFunc for insecure_skip_tls_verify was sending an empty string instead of a bool. Fixes to default to `false`. --- backend/remote-state/manta/backend.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/remote-state/manta/backend.go b/backend/remote-state/manta/backend.go index d4ec85c9c..a3fdfe641 100644 --- a/backend/remote-state/manta/backend.go +++ b/backend/remote-state/manta/backend.go @@ -53,7 +53,7 @@ func New() backend.Backend { "insecure_skip_tls_verify": { Type: schema.TypeBool, Optional: true, - DefaultFunc: schema.EnvDefaultFunc("TRITON_SKIP_TLS_VERIFY", ""), + DefaultFunc: schema.EnvDefaultFunc("TRITON_SKIP_TLS_VERIFY", false), }, "path": { @@ -131,6 +131,9 @@ func (b *Backend) configure(ctx context.Context) error { if data.Get("key_id").(string) == "" { validationError = multierror.Append(validationError, errors.New("`Key ID` must be configured for the Triton provider")) } + if data.Get("key_id").(string) == "" { + validationError = multierror.Append(validationError, errors.New("`Key ID` must be configured for the Triton provider")) + } if b.path == "" { validationError = multierror.Append(validationError, errors.New("`Path` must be configured for the Triton provider")) } From 68dfc3046dab5a26fe901982882690977e6415ac Mon Sep 17 00:00:00 2001 From: Kristin Laemmert Date: Thu, 26 Sep 2019 11:30:52 -0400 Subject: [PATCH 4/4] backend/remote-state: etcdv3, oss, and manta acc tests should fail faster The acceptance tests for etcdv3, oss and manta were not validating required env variablea, chosing to assume that if one was running acceptance tests they had already configured the credentials. It was not always clear if this was a bug in the tests or the provider, so I opted to make the tests fail faster when required attributes were unset (or ""). --- backend/remote-state/etcdv3/backend_test.go | 4 ++++ backend/remote-state/manta/backend.go | 3 --- backend/remote-state/manta/backend_test.go | 8 ++++++++ backend/remote-state/oss/backend_test.go | 6 +++++- internal/initwd/from_module_test.go | 5 +++++ internal/initwd/module_install_test.go | 8 ++++++++ 6 files changed, 30 insertions(+), 4 deletions(-) diff --git a/backend/remote-state/etcdv3/backend_test.go b/backend/remote-state/etcdv3/backend_test.go index 1199dc978..b37f8e3e5 100644 --- a/backend/remote-state/etcdv3/backend_test.go +++ b/backend/remote-state/etcdv3/backend_test.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "os" + "reflect" "strings" "testing" "time" @@ -45,6 +46,9 @@ func prepareEtcdv3(t *testing.T) { t.Log("etcd server tests require setting TF_ACC or TF_ETCDV3_TEST") t.Skip() } + if reflect.DeepEqual(etcdv3Endpoints, []string{""}) { + t.Fatal("etcd server tests require setting TF_ETCDV3_ENDPOINTS") + } cleanupEtcdv3(t) } diff --git a/backend/remote-state/manta/backend.go b/backend/remote-state/manta/backend.go index a3fdfe641..9189ad890 100644 --- a/backend/remote-state/manta/backend.go +++ b/backend/remote-state/manta/backend.go @@ -131,9 +131,6 @@ func (b *Backend) configure(ctx context.Context) error { if data.Get("key_id").(string) == "" { validationError = multierror.Append(validationError, errors.New("`Key ID` must be configured for the Triton provider")) } - if data.Get("key_id").(string) == "" { - validationError = multierror.Append(validationError, errors.New("`Key ID` must be configured for the Triton provider")) - } if b.path == "" { validationError = multierror.Append(validationError, errors.New("`Path` must be configured for the Triton provider")) } diff --git a/backend/remote-state/manta/backend_test.go b/backend/remote-state/manta/backend_test.go index 7e53b928e..be9b2575d 100644 --- a/backend/remote-state/manta/backend_test.go +++ b/backend/remote-state/manta/backend_test.go @@ -18,6 +18,14 @@ func testACC(t *testing.T) { t.Log("Manta backend tests require setting TF_ACC or TF_MANTA_TEST") t.Skip() } + skip = os.Getenv("TRITON_ACCOUNT") == "" && os.Getenv("SDC_ACCOUNT") == "" + if skip { + t.Fatal("Manta backend tests require setting TRITON_ACCOUNT or SDC_ACCOUNT") + } + skip = os.Getenv("TRITON_KEY_ID") == "" && os.Getenv("SDC_KEY_ID") == "" + if skip { + t.Fatal("Manta backend tests require setting TRITON_KEY_ID or SDC_KEY_ID") + } } func TestBackend_impl(t *testing.T) { diff --git a/backend/remote-state/oss/backend_test.go b/backend/remote-state/oss/backend_test.go index 16e717eb7..c71ed2325 100644 --- a/backend/remote-state/oss/backend_test.go +++ b/backend/remote-state/oss/backend_test.go @@ -6,11 +6,12 @@ import ( "testing" "time" + "strings" + "github.com/aliyun/aliyun-oss-go-sdk/oss" "github.com/aliyun/aliyun-tablestore-go-sdk/tablestore" "github.com/hashicorp/terraform/backend" "github.com/hashicorp/terraform/configs/hcl2shim" - "strings" ) // verify that we are doing ACC tests or the OSS tests specifically @@ -20,6 +21,9 @@ func testACC(t *testing.T) { t.Log("oss backend tests require setting TF_ACC or TF_OSS_TEST") t.Skip() } + if skip { + t.Fatal("oss backend tests require setting ALICLOUD_ACCESS_KEY or ALICLOUD_ACCESS_KEY_ID") + } if os.Getenv("ALICLOUD_REGION") == "" { os.Setenv("ALICLOUD_REGION", "cn-beijing") } diff --git a/internal/initwd/from_module_test.go b/internal/initwd/from_module_test.go index b467552b5..f45e2b324 100644 --- a/internal/initwd/from_module_test.go +++ b/internal/initwd/from_module_test.go @@ -20,6 +20,11 @@ func TestDirFromModule_registry(t *testing.T) { fixtureDir := filepath.Clean("testdata/empty") tmpDir, done := tempChdir(t, fixtureDir) + + // the module installer runs filepath.EvalSymlinks() on the destination + // directory before copying files, and the resultant directory is what is + // returned by the install hooks. Without this, tests could fail on machines + // where the default temp dir was a symlink. dir, err := filepath.EvalSymlinks(tmpDir) if err != nil { t.Error(err) diff --git a/internal/initwd/module_install_test.go b/internal/initwd/module_install_test.go index 786f84400..444968169 100644 --- a/internal/initwd/module_install_test.go +++ b/internal/initwd/module_install_test.go @@ -233,6 +233,10 @@ func TestLoaderInstallModules_registry(t *testing.T) { fixtureDir := filepath.Clean("testdata/registry-modules") tmpDir, done := tempChdir(t, fixtureDir) + // the module installer runs filepath.EvalSymlinks() on the destination + // directory before copying files, and the resultant directory is what is + // returned by the install hooks. Without this, tests could fail on machines + // where the default temp dir was a symlink. dir, err := filepath.EvalSymlinks(tmpDir) if err != nil { t.Error(err) @@ -365,6 +369,10 @@ func TestLoaderInstallModules_goGetter(t *testing.T) { fixtureDir := filepath.Clean("testdata/go-getter-modules") tmpDir, done := tempChdir(t, fixtureDir) + // the module installer runs filepath.EvalSymlinks() on the destination + // directory before copying files, and the resultant directory is what is + // returned by the install hooks. Without this, tests could fail on machines + // where the default temp dir was a symlink. dir, err := filepath.EvalSymlinks(tmpDir) if err != nil { t.Error(err)