From 553b8c6de52bc859337af536c36cc1e72d646a1e Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 17 Aug 2022 16:27:58 -0400 Subject: [PATCH] expand module subdir globs --- .../command/e2etest/module_archive_test.go | 32 +++++++++++++++++++ .../e2etest/testdata/module-archive/main.tf | 5 +++ internal/initwd/module_install.go | 7 ++-- 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 internal/command/e2etest/module_archive_test.go create mode 100644 internal/command/e2etest/testdata/module-archive/main.tf diff --git a/internal/command/e2etest/module_archive_test.go b/internal/command/e2etest/module_archive_test.go new file mode 100644 index 0000000000..cb6a2979fd --- /dev/null +++ b/internal/command/e2etest/module_archive_test.go @@ -0,0 +1,32 @@ +package e2etest + +import ( + "path/filepath" + "strings" + "testing" + + "github.com/hashicorp/terraform/internal/e2e" +) + +func TestInitModuleArchive(t *testing.T) { + t.Parallel() + + // this fetches a module archive from github + skipIfCannotAccessNetwork(t) + + fixturePath := filepath.Join("testdata", "module-archive") + tf := e2e.NewBinary(t, terraformBin, fixturePath) + + stdout, stderr, err := tf.Run("init") + if err != nil { + t.Errorf("unexpected error: %s", err) + } + + if stderr != "" { + t.Errorf("unexpected stderr output:\n%s", stderr) + } + + if !strings.Contains(stdout, "Terraform has been successfully initialized!") { + t.Errorf("success message is missing from output:\n%s", stdout) + } +} diff --git a/internal/command/e2etest/testdata/module-archive/main.tf b/internal/command/e2etest/testdata/module-archive/main.tf new file mode 100644 index 0000000000..8101c8094e --- /dev/null +++ b/internal/command/e2etest/testdata/module-archive/main.tf @@ -0,0 +1,5 @@ +// this should be able to unpack the tarball and change the module directory to +// the archive directory regardless of its name. +module "bucket" { + source = "https://github.com/terraform-aws-modules/terraform-aws-s3-bucket/archive/v3.3.0.tar.gz//*?archive=tar.gz" +} diff --git a/internal/initwd/module_install.go b/internal/initwd/module_install.go index 0bc971860a..adc5dec5ec 100644 --- a/internal/initwd/module_install.go +++ b/internal/initwd/module_install.go @@ -587,8 +587,11 @@ func (i *ModuleInstaller) installGoGetterModule(ctx context.Context, req *earlyc return nil, diags } - subDir := filepath.FromSlash(addr.Subdir) - modDir := filepath.Join(instPath, subDir) + modDir, err := getmodules.ExpandSubdirGlobs(instPath, addr.Subdir) + if err != nil { + diags = diags.Append(err) + return nil, diags + } log.Printf("[TRACE] ModuleInstaller: %s %q was downloaded to %s", key, addr, modDir)