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
3245func newUI (out io.Writer , err io.Writer ) cli.Ui {
3346
@@ -114,20 +127,26 @@ func InternalPlugin(args []string) int {
114127}
115128
116129func 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
123138func 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
130147func 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
138157func 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
145166func 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
152175func 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