|
@ -25,6 +25,7 @@ type ( |
|
|
Vars map[string]string |
|
|
Vars map[string]string |
|
|
Secrets map[string]string |
|
|
Secrets map[string]string |
|
|
InitOptions InitOptions |
|
|
InitOptions InitOptions |
|
|
|
|
|
FmtOptions FmtOptions |
|
|
Cacert string |
|
|
Cacert string |
|
|
Sensitive bool |
|
|
Sensitive bool |
|
|
RoleARN string |
|
|
RoleARN string |
|
@ -48,6 +49,14 @@ type ( |
|
|
LockTimeout string `json:"lock-timeout"` |
|
|
LockTimeout string `json:"lock-timeout"` |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// FmtOptions fmt options for the Terraform's fmt command
|
|
|
|
|
|
FmtOptions struct { |
|
|
|
|
|
List *bool `json:"list"` |
|
|
|
|
|
Write *bool `json:"write"` |
|
|
|
|
|
Diff *bool `json:"diff"` |
|
|
|
|
|
Check *bool `json:"check"` |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Plugin represents the plugin instance to be executed
|
|
|
// Plugin represents the plugin instance to be executed
|
|
|
Plugin struct { |
|
|
Plugin struct { |
|
|
Config Config |
|
|
Config Config |
|
@ -94,6 +103,8 @@ func (p Plugin) Exec() error { |
|
|
// Add commands listed from Actions
|
|
|
// Add commands listed from Actions
|
|
|
for _, action := range p.Config.Actions { |
|
|
for _, action := range p.Config.Actions { |
|
|
switch action { |
|
|
switch action { |
|
|
|
|
|
case "fmt": |
|
|
|
|
|
commands = append(commands, tfFmt(p.Config)) |
|
|
case "validate": |
|
|
case "validate": |
|
|
commands = append(commands, tfValidate(p.Config)) |
|
|
commands = append(commands, tfValidate(p.Config)) |
|
|
case "plan": |
|
|
case "plan": |
|
@ -105,7 +116,7 @@ func (p Plugin) Exec() error { |
|
|
case "destroy": |
|
|
case "destroy": |
|
|
commands = append(commands, tfDestroy(p.Config)) |
|
|
commands = append(commands, tfDestroy(p.Config)) |
|
|
default: |
|
|
default: |
|
|
return fmt.Errorf("valid actions are: validate, plan, apply, plan-destroy, destroy. You provided %s", action) |
|
|
return fmt.Errorf("valid actions are: fmt, validate, plan, apply, plan-destroy, destroy. You provided %s", action) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -321,6 +332,28 @@ func tfValidate(config Config) *exec.Cmd { |
|
|
) |
|
|
) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func tfFmt(config Config) *exec.Cmd { |
|
|
|
|
|
args := []string{ |
|
|
|
|
|
"fmt", |
|
|
|
|
|
} |
|
|
|
|
|
if config.FmtOptions.List != nil { |
|
|
|
|
|
args = append(args, fmt.Sprintf("-list=%t", *config.FmtOptions.List)) |
|
|
|
|
|
} |
|
|
|
|
|
if config.FmtOptions.Write != nil { |
|
|
|
|
|
args = append(args, fmt.Sprintf("-write=%t", *config.FmtOptions.Write)) |
|
|
|
|
|
} |
|
|
|
|
|
if config.FmtOptions.Diff != nil { |
|
|
|
|
|
args = append(args, fmt.Sprintf("-diff=%t", *config.FmtOptions.Diff)) |
|
|
|
|
|
} |
|
|
|
|
|
if config.FmtOptions.Check != nil { |
|
|
|
|
|
args = append(args, fmt.Sprintf("-check=%t", *config.FmtOptions.Check)) |
|
|
|
|
|
} |
|
|
|
|
|
return exec.Command( |
|
|
|
|
|
"terraform", |
|
|
|
|
|
args..., |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func vars(vs map[string]string) []string { |
|
|
func vars(vs map[string]string) []string { |
|
|
var args []string |
|
|
var args []string |
|
|
for k, v := range vs { |
|
|
for k, v := range vs { |
|
|