expand module subdir globs

This commit is contained in:
James Bardin 2022-08-17 16:27:58 -04:00
parent ec9c67e9ca
commit 553b8c6de5
3 changed files with 42 additions and 2 deletions

View File

@ -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)
}
}

View File

@ -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"
}

View File

@ -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)