mirror of
https://github.com/thegeeklab/wp-opentofu.git
synced 2024-11-25 09:40:39 +00:00
added ability to pass -var-file args to plan
This commit is contained in:
parent
2d3b9fd201
commit
eede51fea6
4
DOCS.md
4
DOCS.md
@ -188,6 +188,10 @@ vars
|
|||||||
: a map of variables to pass to the Terraform `plan` and `apply` commands.
|
: a map of variables to pass to the Terraform `plan` and `apply` commands.
|
||||||
Each value is passed as a `-var <key>=<value>` option.
|
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
|
secrets
|
||||||
: a map of variables to pass to the Terraform `plan` and `apply` commands as well as setting envvars.
|
: 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.
|
The `key` is the var and ENV to set. The `value` is the ENV to read the value from.
|
||||||
|
7
main.go
7
main.go
@ -79,6 +79,12 @@ func main() {
|
|||||||
Usage: "targets to run apply or plan on",
|
Usage: "targets to run apply or plan on",
|
||||||
EnvVar: "PLUGIN_TARGETS",
|
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 {
|
if err := app.Run(os.Args); err != nil {
|
||||||
@ -123,6 +129,7 @@ func run(c *cli.Context) error {
|
|||||||
RootDir: c.String("root_dir"),
|
RootDir: c.String("root_dir"),
|
||||||
Parallelism: c.Int("parallelism"),
|
Parallelism: c.Int("parallelism"),
|
||||||
Targets: c.StringSlice("targets"),
|
Targets: c.StringSlice("targets"),
|
||||||
|
VarFiles: c.StringSlice("var_files"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
19
plugin.go
19
plugin.go
@ -2,16 +2,17 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"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"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"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 (
|
type (
|
||||||
@ -26,6 +27,7 @@ type (
|
|||||||
RootDir string
|
RootDir string
|
||||||
Parallelism int
|
Parallelism int
|
||||||
Targets []string
|
Targets []string
|
||||||
|
VarFiles []string
|
||||||
}
|
}
|
||||||
|
|
||||||
Remote struct {
|
Remote struct {
|
||||||
@ -59,7 +61,7 @@ func (p Plugin) Exec() error {
|
|||||||
}
|
}
|
||||||
commands = append(commands, getModules())
|
commands = append(commands, getModules())
|
||||||
commands = append(commands, validateCommand())
|
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 {
|
if !p.Config.Plan {
|
||||||
commands = append(commands, applyCommand(p.Config.Parallelism, p.Config.Targets))
|
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{
|
args := []string{
|
||||||
"plan",
|
"plan",
|
||||||
"-out=plan.tfout",
|
"-out=plan.tfout",
|
||||||
@ -154,6 +156,9 @@ func planCommand(variables map[string]string, secrets map[string]string, paralle
|
|||||||
for _, v := range targets {
|
for _, v := range targets {
|
||||||
args = append(args, "--target", fmt.Sprintf("%s", v))
|
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 {
|
for k, v := range variables {
|
||||||
args = append(args, "-var")
|
args = append(args, "-var")
|
||||||
args = append(args, fmt.Sprintf("%s=%s", k, v))
|
args = append(args, fmt.Sprintf("%s=%s", k, v))
|
||||||
|
Loading…
Reference in New Issue
Block a user