From 1847409c8d1cb007712b217181f1031e788beb28 Mon Sep 17 00:00:00 2001 From: Joachim Hill-Grannec Date: Sat, 6 May 2017 18:06:28 -0700 Subject: [PATCH] updates to work with terraform 0.9.4 --- Dockerfile | 2 +- plugin.go | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index a8afcaf..b62e4ba 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,7 @@ RUN apk -U add \ wget && \ rm -rf /var/cache/apk/* -ENV TERRAFORM_VERSION 0.9.2 +ENV TERRAFORM_VERSION 0.9.4 RUN wget -q https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip -O terraform.zip && \ unzip terraform.zip -d /bin && \ rm -f terraform.zip diff --git a/plugin.go b/plugin.go index b90d39e..b5ab35d 100644 --- a/plugin.go +++ b/plugin.go @@ -58,6 +58,7 @@ func (p Plugin) Exec() error { commands = append(commands, remoteConfigCommand(remote)) } commands = append(commands, getModules()) + commands = append(commands, initCommand()) commands = append(commands, validateCommand()) commands = append(commands, planCommand(p.Config.Vars, p.Config.Secrets, p.Config.Parallelism, p.Config.Targets)) if !p.Config.Plan { @@ -102,7 +103,7 @@ func installCaCert(cacert string) *exec.Cmd { func exportSecrets(secrets map[string]string) { for k, v := range secrets { - os.Setenv(fmt.Sprintf("%s", k), fmt.Sprintf("%s", os.Getenv(v))) + os.Setenv(k, v) } } @@ -146,8 +147,14 @@ func validateCommand() *exec.Cmd { ) } +func initCommand() * exec.Cmd { + return exec.Command("terraform", "init",) +} + + func planCommand(variables map[string]string, secrets map[string]string, parallelism int, targets []string) *exec.Cmd { - args := []string{ + exportSecrets(secrets) + args := []string{ "plan", "-out=plan.tfout", } @@ -158,10 +165,6 @@ func planCommand(variables map[string]string, secrets map[string]string, paralle args = append(args, "-var") args = append(args, fmt.Sprintf("%s=%s", k, v)) } - for k, v := range secrets { - args = append(args, "-var") - args = append(args, fmt.Sprintf("%s=%s", k, os.Getenv(v))) - } if parallelism > 0 { args = append(args, fmt.Sprintf("-parallelism=%d", parallelism)) }