Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs/clarify go dependency #135

Merged
merged 3 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 33 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@
# m1-terraform-provider-helper

[![Release](https://img.shields.io/github/v/release/kreuzwerker/m1-terraform-provider-helper)](https://github.com/kreuzwerker/m1-terraform-provider-helper/releases)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/kreuzwerker/m1-terraform-provider-helper/blob/main/LICENSE)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/kreuzwerker/m1-terraform-provider-helper/blob/main/LICENSE)
[![Go Status](https://github.com/kreuzwerker/m1-terraform-provider-helper/workflows/tests/badge.svg)](https://github.com/kreuzwerker/m1-terraform-provider-helper/actions)
[![Lint Status](https://github.com/kreuzwerker/m1-terraform-provider-helper/workflows/golangci-lint/badge.svg)](https://github.com/kreuzwerker/m1-terraform-provider-helper/actions)
[![Go Report Card](https://goreportcard.com/badge/github.com/kreuzwerker/m1-terraform-provider-helper)](https://goreportcard.com/report/github.com/kreuzwerker/m1-terraform-provider-helper)
[![Go Report Card](https://goreportcard.com/badge/github.com/kreuzwerker/m1-terraform-provider-helper)](https://goreportcard.com/report/github.com/kreuzwerker/m1-terraform-provider-helper)

A CLI to help with managing the installation and compilation of terraform providers when running a new M1 Mac.
A CLI to manage the installation and compilation of Terraform providers for an ARM-based Mac.

## Table of Contents

- [m1-terraform-provider-helper](#m1-terraform-provider-helper)
- [Table of Contents](#table-of-contents)
- [Motivation](#motivation)
- [Installation](#installation)
- [Dependencies](#dependencies)
- [Usage](#usage)
- [Debugging Installation Problems](#debugging-installation-problems)
- [Terraform Lockfile handling](#terraform-lockfile-handling)
Expand All @@ -35,38 +36,56 @@ A CLI to help with managing the installation and compilation of terraform provid
- [License](#license)
## Motivation

While using my new Macbook with M1 chip I often encountered issues in client projects when working with Terraform projects. Either some terraform providers have no adapted to the new `darwin_arm64` at all or the version of the used provider is pinned to an older version. In both cases, there is no pre-compiled binary for `darwin_arm64` => you have to compile it yourself. There is a nice writeup on how to compile in a [Terraform Issue](https://github.com/hashicorp/terraform/issues/27257#issuecomment-754777716). As I am constantly switching forth and back between using own-compiled binaries and pre-build, I wanted to have an elegant solution which manages all the details by itself.
While using my then-new MacBook with an M1 chip, I often encountered issues in client projects when
working with Terraform. Some Terraform providers hadn't adapted to the new `darwin_arm64` architecture at
all, or else the provider was pinned to an older, incompatible version. In both cases, there was no
pre-compiled binary for `darwin_arm64`; you had to compile it yourself. (There's a nice write-up on how to
compile in a
[Terraform Issue](https://github.com/hashicorp/terraform/issues/27257#issuecomment-754777716).) As I was
constantly switching back and forth between own-compiled binaries and pre-built ones, I wanted an elegant
solution that managed all the details by itself.

## Installation

```sh
brew install kreuzwerker/taps/m1-terraform-provider-helper
```

### Dependencies

Since Go is used to build the providers, you need to have a working Go setup in the local directory where you run m1-terraform-provider-helper
commands. Although Go is installed by Homebrew as a dependency
of m1-terraform-provider-helper, the Go binary won't necessarily be in your PATH. (For example, if you use
asdf or a similar version manager for Go, the version manager's shim likely comes before Homebrew's Go
binary in your PATH.) Ensure that the command `go version` succeeds before using this tool.

## Usage

```
A CLI to manage the installation of terraform providers for the Mac M1 chip
A CLI to manage the installation of Terraform providers for an ARM-based Mac

Usage:
m1-terraform-provider-helper [command]

Available Commands:
activate Activate the usage of m1 provider helper
deactivate Deactivate the usage of M1 provider helper
activate Activate the m1-terraform-provider-helper
completion Generate the autocompletion script for the specified shell
deactivate Deactivate the m1-terraform-provider-helper
help Help about any command
install Downloads (and compiles) a terraform provider for the M1 chip
list Lists all available providers and their versions
lockfile Commands to work with terraform lockfiles
status Shows the status of the m1 provider installations
install Download (and compile) a Terraform provider for an ARM-based Mac
list List all available providers and their versions
lockfile Commands to work with Terraform lockfiles
status Show the status of the m1-terraform-provider-helper installation
version Display the current version

Flags:
-h, --help help for m1-terraform-provider-helper

Use "m1-terraform-provider-helper [command] --help" for more information about a command.
```

Example:
You want to install the `terraform-provider-vault` in version `v2.10.0` because you are using it in a project and let's assume it has no pre-build binary for Mac M1:
You want to install version `v2.10.0` of `terraform-provider-vault` because you're using it in a project. Let's assume it has no pre-built binary for an ARM-based Mac:

```sh
m1-terraform-provider-helper activate # (In case you have not activated the helper)
Expand Down Expand Up @@ -97,7 +116,7 @@ checksums previously recorded in the dependency lock file.
The reason is that the checksums inside the existing lockfile are the checksum of the previously installed `darwin_amd64` provider. Now we are using our own `darwin_arm64` compiled provider, which has a different checksum. In order to make `terraform init` work again, we have to add the checksum of the local provider to the lockfile.

This is done via the `m1-terraform-provider-helper lockfile upgrade` command. It also two flags which you can use to specify the input/output lockfile:
* `--input-lockfile-path`
* `--input-lockfile-path`
* `--output-path`


Expand Down Expand Up @@ -166,7 +185,7 @@ If you want it automated prepend `TAG=1` to the command as follows:
```sh
# TAG=1 indicates to tag and generate the changelog
TAG=1 make minor
git push origin main --tags
git push origin main --tags
```

## License
Expand Down
2 changes: 1 addition & 1 deletion cmd/activate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
func activateCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "activate",
Short: "Activate the usage of m1 provider helper",
Short: "Activate the m1-terraform-provider-helper",

RunE: func(cmd *cobra.Command, args []string) error {
a := app.New()
Expand Down
2 changes: 1 addition & 1 deletion cmd/deactivate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
func deactivateCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "deactivate",
Short: "Deactivate the usage of M1 provider helper",
Short: "Deactivate the m1-terraform-provider-helper",

RunE: func(cmd *cobra.Command, args []string) error {
a := app.New()
Expand Down
4 changes: 2 additions & 2 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func installCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "install [providerName]",
Args: cobra.ExactArgs(1),
Short: "Downloads (and compiles) a Terraform provider for the M1 chip",
Long: "Download and compiles the specific Terraform provider for your M1 chip. Provider name is the Terraform registry identifier, e.g. \"hashicorp/aws\"",
Short: "Download (and compile) a Terraform provider for an ARM-based Mac",
Long: "Download and compile a specific Terraform provider for an ARM-based Mac. Provider name is the Terraform registry identifier (e.g., \"hashicorp/aws\")",
RunE: func(cmd *cobra.Command, args []string) error {
a := app.New()
a.Init()
Expand Down
2 changes: 1 addition & 1 deletion cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
func listCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "Lists all available providers and their versions",
Short: "List all available providers and their versions",

RunE: func(cmd *cobra.Command, args []string) error {
a := app.New()
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
func RootCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "m1-terraform-provider-helper",
Short: "A CLI to manage the installation of Terraform providers for the Mac M1 chip",
Short: "A CLI to manage the installation of Terraform providers for an ARM-based Mac",
}

cmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
func statusCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "status",
Short: "Shows the status of the m1 provider installations",
Short: "Show the status of the m1-terraform-provider-helper installation",

RunE: func(cmd *cobra.Command, args []string) error {
a := app.New()
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const version string = "0.8.2"
func versionCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "version",
Short: "Displays the current version",
Short: "Display the current version",

RunE: func(cmd *cobra.Command, args []string) error {
fmt.Fprintf(os.Stdout, "Current version: %s", version)
Expand Down