|
@ -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)) |
|
|