Skip to content

Commit

Permalink
Merge pull request #10 from etsy/feat-custom-arch
Browse files Browse the repository at this point in the history
feat: add custom arch support w/ env var
  • Loading branch information
ericnorris authored Apr 26, 2022
2 parents 9a1b0f2 + 2fe4634 commit 3bd203b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ A seamless launcher for Terraform.

Simply navigate to any folder that contains Terraform configuration and run `terraform` as you usually would. `terraform-demux` will attempt to locate the appropriate [version constraint](https://www.terraform.io/docs/language/expressions/version-constraints.html) by searching in the current working directory and recursively through parent directories. If `terraform-demux` cannot determine a constraint, it will default to the latest possible version.

### Architecture Compatability

`terraform-demux` supports a native `arm64` build that can also run `amd64` versions of `terraform` by specifying the `TF_DEMUX_ARCH` environment variable. This might be necessary for `terraform` workspaces that need older `terraform` versions that do not have `arm64` builds, or use older providers that do not have `arm64` builds.

It is recommended to set up the following shell alias for handy `amd64` invocations:

```sh
alias terraform-amd64="TF_DEMUX_ARCH=amd64 terraform-demux"
```

### Logging

Setting the `TF_DEMUX_LOG` environment variable to any non-empty value will cause `terraform-demux` to write out debug logs to `stderr`.
Expand Down
11 changes: 9 additions & 2 deletions cmd/terraform-demux/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io/ioutil"
"log"
"os"
"runtime"

"github.com/etsy/terraform-demux/internal/wrapper"
)
Expand All @@ -17,9 +18,15 @@ func main() {
log.SetOutput(ioutil.Discard)
}

log.Printf("terraform-demux version %s", version)
arch := os.Getenv("TF_DEMUX_ARCH")

exitCode, err := wrapper.RunTerraform(os.Args[1:])
if arch == "" {
arch = runtime.GOARCH
}

log.Printf("terraform-demux version %s, using arch '%s'", version, arch)

exitCode, err := wrapper.RunTerraform(os.Args[1:], arch)

if err != nil {
log.SetOutput(os.Stderr)
Expand Down
4 changes: 2 additions & 2 deletions internal/wrapper/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/pkg/errors"
)

func RunTerraform(args []string) (int, error) {
func RunTerraform(args []string, arch string) (int, error) {
cacheDirectory, err := ensureCacheDirectory()

if err != nil {
Expand Down Expand Up @@ -53,7 +53,7 @@ func RunTerraform(args []string) (int, error) {

log.Printf("version '%s' matches all constraints", matchingRelease.Version)

executablePath, err := client.DownloadRelease(matchingRelease, runtime.GOOS, runtime.GOARCH)
executablePath, err := client.DownloadRelease(matchingRelease, runtime.GOOS, arch)

if err != nil {
return 1, err
Expand Down

0 comments on commit 3bd203b

Please sign in to comment.