Skip to content

Commit

Permalink
Drop symlinkAuxiliarProviders helper.
Browse files Browse the repository at this point in the history
We don't actually use this helper anywhere, and it was incompatible with
v1.5.0 of go-getter, for reasons.
  • Loading branch information
paddycarver authored and kmoe committed Sep 30, 2020
1 parent 3e0c079 commit 651b26a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 81 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/hashicorp/errwrap v1.0.0
github.com/hashicorp/go-cleanhttp v0.5.1
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/go-getter v1.5.0
github.com/hashicorp/go-getter v1.5.0 // indirect
github.com/hashicorp/go-hclog v0.9.2
github.com/hashicorp/go-multierror v1.0.0
github.com/hashicorp/go-plugin v1.3.0
Expand Down
80 changes: 0 additions & 80 deletions internal/plugintest/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"strings"

getter "github.com/hashicorp/go-getter"
)

const subprocessCurrentSigil = "4acd63807899403ca4859f5bb948d2c6"
Expand Down Expand Up @@ -85,81 +80,6 @@ func InitHelper(config *Config) (*Helper, error) {
}, nil
}

// symlinkAuxiliaryProviders discovers auxiliary provider binaries, used in
// multi-provider tests, and symlinks them to the plugin directory.
//
// Auxiliary provider binaries should be included in the provider source code
// directory, under the path terraform.d/plugins/$GOOS_$GOARCH/provider-name.
//
// The environment variable TF_ACC_PROVIDER_ROOT_DIR must be set to the path of
// the provider source code directory root in order to use this feature.
func symlinkAuxiliaryProviders(pluginDir string) error {
providerRootDir := os.Getenv("TF_ACC_PROVIDER_ROOT_DIR")
if providerRootDir == "" {
// common case; assume intentional and do not log
return nil
}

_, err := os.Stat(filepath.Join(providerRootDir, "terraform.d", "plugins"))
if os.IsNotExist(err) {
fmt.Printf("No terraform.d/plugins directory found: continuing. Unset TF_ACC_PROVIDER_ROOT_DIR or supply provider binaries in terraform.d/plugins/$GOOS_$GOARCH to disable this message.")
return nil
} else if err != nil {
return fmt.Errorf("Unexpected error: %s", err)
}

auxiliaryProviderDir := filepath.Join(providerRootDir, "terraform.d", "plugins", runtime.GOOS+"_"+runtime.GOARCH)

// If we can't os.Stat() terraform.d/plugins/$GOOS_$GOARCH, however,
// assume the omission was unintentional, and error.
_, err = os.Stat(auxiliaryProviderDir)
if os.IsNotExist(err) {
return fmt.Errorf("error finding auxiliary provider dir %s: %s", auxiliaryProviderDir, err)
} else if err != nil {
return fmt.Errorf("Unexpected error: %s", err)
}

// now find all the providers in that dir and symlink them to the plugin dir
providers, err := ioutil.ReadDir(auxiliaryProviderDir)
if err != nil {
return fmt.Errorf("error reading auxiliary providers: %s", err)
}

zipDecompressor := new(getter.ZipDecompressor)

for _, provider := range providers {
filename := provider.Name()
filenameExt := filepath.Ext(filename)
name := strings.TrimSuffix(filename, filenameExt)
path := filepath.Join(auxiliaryProviderDir, name)
symlinkPath := filepath.Join(pluginDir, name)

// exit early if we have already symlinked this provider
_, err := os.Stat(symlinkPath)
if err == nil {
continue
}

// if filename ends in .zip, assume it is a zip and extract it
// otherwise assume it is a provider binary
if filenameExt == ".zip" {
_, err = os.Stat(path)
if os.IsNotExist(err) {
zipDecompressor.Decompress(path, filepath.Join(auxiliaryProviderDir, filename), false)
} else if err != nil {
return fmt.Errorf("Unexpected error: %s", err)
}
}

err = symlinkFile(path, symlinkPath)
if err != nil {
return fmt.Errorf("error symlinking auxiliary provider %s: %s", name, err)
}
}

return nil
}

// Close cleans up temporary files and directories created to support this
// helper, returning an error if any of the cleanup fails.
//
Expand Down

0 comments on commit 651b26a

Please sign in to comment.