0
0
mirror of https://github.com/thegeeklab/wp-opentofu.git synced 2024-11-09 18:00:40 +00:00

Merge pull request #35 from nmaki/var-files

added ability to pass -var-file args to plan
This commit is contained in:
Jacob McCann 2017-05-09 11:23:45 -05:00 committed by GitHub
commit 0ee8895860
3 changed files with 23 additions and 7 deletions

View File

@ -188,6 +188,10 @@ vars
: a map of variables to pass to the Terraform `plan` and `apply` commands.
Each value is passed as a `-var <key>=<value>` option.
var_files
: a list of variable files to pass to the Terraform `plan` and `apply` commands.
Each value is passed as a `-var-file <value>` option.
secrets
: a map of variables to pass to the Terraform `plan` and `apply` commands as well as setting envvars.
The `key` is the var and ENV to set. The `value` is the ENV to read the value from.

View File

@ -79,6 +79,12 @@ func main() {
Usage: "targets to run apply or plan on",
EnvVar: "PLUGIN_TARGETS",
},
cli.StringSliceFlag{
Name: "var_files",
Usage: "a list of var files to use. Each value is passed as -var-file=<value>",
EnvVar: "PLUGIN_VAR_FILES",
},
}
if err := app.Run(os.Args); err != nil {
@ -123,6 +129,7 @@ func run(c *cli.Context) error {
RootDir: c.String("root_dir"),
Parallelism: c.Int("parallelism"),
Targets: c.StringSlice("targets"),
VarFiles: c.StringSlice("var_files"),
},
}

View File

@ -2,16 +2,17 @@ package main
import (
"fmt"
"github.com/Sirupsen/logrus"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/sts"
"io/ioutil"
"os"
"os/exec"
"strings"
"time"
"github.com/Sirupsen/logrus"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/sts"
)
type (
@ -26,6 +27,7 @@ type (
RootDir string
Parallelism int
Targets []string
VarFiles []string
}
Remote struct {
@ -59,7 +61,7 @@ func (p Plugin) Exec() error {
}
commands = append(commands, getModules())
commands = append(commands, validateCommand())
commands = append(commands, planCommand(p.Config.Vars, p.Config.Secrets, p.Config.Parallelism, p.Config.Targets))
commands = append(commands, planCommand(p.Config.Vars, p.Config.Secrets, p.Config.Parallelism, p.Config.Targets, p.Config.VarFiles))
if !p.Config.Plan {
commands = append(commands, applyCommand(p.Config.Parallelism, p.Config.Targets))
}
@ -146,7 +148,7 @@ func validateCommand() *exec.Cmd {
)
}
func planCommand(variables map[string]string, secrets map[string]string, parallelism int, targets []string) *exec.Cmd {
func planCommand(variables map[string]string, secrets map[string]string, parallelism int, targets []string, varFiles []string) *exec.Cmd {
args := []string{
"plan",
"-out=plan.tfout",
@ -154,6 +156,9 @@ func planCommand(variables map[string]string, secrets map[string]string, paralle
for _, v := range targets {
args = append(args, "--target", fmt.Sprintf("%s", v))
}
for _, v := range varFiles {
args = append(args, "-var-file", fmt.Sprintf("%s", v))
}
for k, v := range variables {
args = append(args, "-var")
args = append(args, fmt.Sprintf("%s=%s", k, v))