Skip to content

Commit cb228de

Browse files
paultyngPaddy
authored andcommitted
Output copy+pastable values for debug
1 parent 6e57e60 commit cb228de

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

plugin/debug.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"fmt"
88
"os"
99
"os/signal"
10+
"runtime"
11+
"strings"
1012
"time"
1113

1214
"github.com/hashicorp/go-plugin"
@@ -87,14 +89,26 @@ func Debug(ctx context.Context, providerAddr string, opts *ServeOpts) error {
8789
case <-ctx.Done():
8890
}
8991
}()
90-
reattachStr, err := json.Marshal(map[string]ReattachConfig{
92+
reattachBytes, err := json.Marshal(map[string]ReattachConfig{
9193
providerAddr: config,
9294
})
9395
if err != nil {
9496
return fmt.Errorf("Error building reattach string: %w", err)
9597
}
9698

97-
fmt.Printf("Provider server started; to attach Terraform, set TF_REATTACH_PROVIDERS to the following:\n%s\n", string(reattachStr))
99+
reattachStr := string(reattachBytes)
100+
101+
fmt.Printf("Provider started, to attach Terraform set the TF_REATTACH_PROVIDERS env var:\n\n")
102+
switch runtime.GOOS {
103+
case "windows":
104+
fmt.Printf("\tCommand Prompt:\tset \"TF_REATTACH_PROVIDERS=%s\"\n", reattachStr)
105+
fmt.Printf("\tPowerShell:\t$env:TF_REATTACH_PROVIDERS='%s'\n", strings.ReplaceAll(reattachStr, `'`, `''`))
106+
case "linux", "darwin":
107+
fmt.Printf("\tTF_REATTACH_PROVIDERS='%s'\n", strings.ReplaceAll(reattachStr, `'`, `'"'"'`))
108+
default:
109+
fmt.Println(reattachStr)
110+
}
111+
fmt.Println("")
98112

99113
// wait for the server to be done
100114
<-closeCh

0 commit comments

Comments
 (0)