Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit 01ce8ed

Browse files
committed
Initialize the remote state backends
Signed-off-by: Christian Simon <simon@swine.de>
1 parent f387827 commit 01ce8ed

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

cmd/tarmak/cmd/terraform.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package cmd
44
import (
55
"os"
66

7-
"github.com/hashicorp/go-plugin"
87
"github.com/spf13/cobra"
98

109
"github.com/jetstack/tarmak/pkg/tarmak/utils"
@@ -13,7 +12,6 @@ import (
1312

1413
// ensure plugin clients get closed after subcommand run
1514
func terraformPassthrough(args []string, f func([]string, <-chan struct{}) int) int {
16-
defer plugin.CleanupClients()
1715
return f(args, utils.MakeShutdownCh())
1816
}
1917

pkg/terraform/passthrough.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"log"
88
"os"
99

10+
goPlugin "github.com/hashicorp/go-plugin"
11+
backendInit "github.com/hashicorp/terraform/backend/init"
1012
"github.com/hashicorp/terraform/command"
1113
"github.com/hashicorp/terraform/plugin"
1214
"github.com/mitchellh/cli"
@@ -28,6 +30,17 @@ var InternalProviders = map[string]plugin.ProviderFunc{
2830
"template": providertemplate.Provider,
2931
}
3032

33+
// Prepare passthrough environment
34+
func passthroughPrepare() {
35+
// initialise backends
36+
backendInit.Init(nil)
37+
}
38+
39+
func passthroughCleanup() {
40+
// cleanup clients
41+
goPlugin.CleanupClients()
42+
}
43+
3144
// create new terraform ui
3245
func newUI(out io.Writer, err io.Writer) cli.Ui {
3346

@@ -114,20 +127,26 @@ func InternalPlugin(args []string) int {
114127
}
115128

116129
func Plan(args []string, stopCh <-chan struct{}) int {
130+
passthroughPrepare()
131+
defer passthroughCleanup()
117132
c := &command.PlanCommand{
118133
Meta: newMeta(newUI(os.Stdout, os.Stderr), stopCh),
119134
}
120135
return c.Run(args)
121136
}
122137

123138
func Apply(args []string, stopCh <-chan struct{}) int {
139+
passthroughPrepare()
140+
defer passthroughCleanup()
124141
c := &command.ApplyCommand{
125142
Meta: newMeta(newUI(os.Stdout, os.Stderr), stopCh),
126143
}
127144
return c.Run(args)
128145
}
129146

130147
func Destroy(args []string, stopCh <-chan struct{}) int {
148+
passthroughPrepare()
149+
defer passthroughCleanup()
131150
c := &command.ApplyCommand{
132151
Meta: newMeta(newUI(os.Stdout, os.Stderr), stopCh),
133152
Destroy: true,
@@ -136,20 +155,26 @@ func Destroy(args []string, stopCh <-chan struct{}) int {
136155
}
137156

138157
func Init(args []string, stopCh <-chan struct{}) int {
158+
passthroughPrepare()
159+
defer passthroughCleanup()
139160
c := &command.InitCommand{
140161
Meta: newMeta(newUI(os.Stdout, os.Stderr), stopCh),
141162
}
142163
return c.Run(args)
143164
}
144165

145166
func Output(args []string, stopCh <-chan struct{}) int {
167+
passthroughPrepare()
168+
defer passthroughCleanup()
146169
c := &command.OutputCommand{
147170
Meta: newMeta(newUI(os.Stdout, os.Stderr), stopCh),
148171
}
149172
return c.Run(args)
150173
}
151174

152175
func Unlock(args []string, stopCh <-chan struct{}) int {
176+
passthroughPrepare()
177+
defer passthroughCleanup()
153178
c := &command.UnlockCommand{
154179
Meta: newMeta(newUI(os.Stdout, os.Stderr), stopCh),
155180
}

0 commit comments

Comments
 (0)