|
@ -26,8 +26,11 @@ type ( |
|
|
Secrets map[string]string |
|
|
Secrets map[string]string |
|
|
InitOptions InitOptions |
|
|
InitOptions InitOptions |
|
|
FmtOptions FmtOptions |
|
|
FmtOptions FmtOptions |
|
|
|
|
|
SummarizeOptions SummarizeOptions |
|
|
Cacert string |
|
|
Cacert string |
|
|
Sensitive bool |
|
|
Sensitive bool |
|
|
|
|
|
SkipInit bool |
|
|
|
|
|
SkipCleanup bool |
|
|
RoleARN string |
|
|
RoleARN string |
|
|
RootDir string |
|
|
RootDir string |
|
|
Parallelism int |
|
|
Parallelism int |
|
@ -59,6 +62,14 @@ type ( |
|
|
Check *bool `json:"check"` |
|
|
Check *bool `json:"check"` |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// SummarizeOptions for tf-summarize
|
|
|
|
|
|
SummarizeOptions struct { |
|
|
|
|
|
Draw *bool `json:"draw"` |
|
|
|
|
|
Md *bool `json:"md"` |
|
|
|
|
|
Tree *bool `json:"tree"` |
|
|
|
|
|
SeparateTree *bool `json:"separate_tree"` |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Plugin represents the plugin instance to be executed
|
|
|
// Plugin represents the plugin instance to be executed
|
|
|
Plugin struct { |
|
|
Plugin struct { |
|
|
Config Config |
|
|
Config Config |
|
@ -104,9 +115,11 @@ func (p Plugin) Exec() error { |
|
|
commands = append(commands, installCaCert(p.Config.Cacert)) |
|
|
commands = append(commands, installCaCert(p.Config.Cacert)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
commands = append(commands, deleteCache(terraformDataDir)) |
|
|
if !p.Config.SkipInit { |
|
|
commands = append(commands, initCommand(p.Config.InitOptions)) |
|
|
commands = append(commands, deleteCache(terraformDataDir)) |
|
|
commands = append(commands, getModules()) |
|
|
commands = append(commands, initCommand(p.Config.InitOptions)) |
|
|
|
|
|
commands = append(commands, getModules()) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Add commands listed from Actions
|
|
|
// Add commands listed from Actions
|
|
|
for _, action := range p.Config.Actions { |
|
|
for _, action := range p.Config.Actions { |
|
@ -119,6 +132,8 @@ func (p Plugin) Exec() error { |
|
|
commands = append(commands, tfPlan(p.Config, false)) |
|
|
commands = append(commands, tfPlan(p.Config, false)) |
|
|
case "plan-destroy": |
|
|
case "plan-destroy": |
|
|
commands = append(commands, tfPlan(p.Config, true)) |
|
|
commands = append(commands, tfPlan(p.Config, true)) |
|
|
|
|
|
case "summarize": |
|
|
|
|
|
commands = append(commands, tfSummary(p.Config)) |
|
|
case "apply": |
|
|
case "apply": |
|
|
commands = append(commands, tfApply(p.Config)) |
|
|
commands = append(commands, tfApply(p.Config)) |
|
|
case "destroy": |
|
|
case "destroy": |
|
@ -128,7 +143,9 @@ func (p Plugin) Exec() error { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
commands = append(commands, deleteCache(terraformDataDir)) |
|
|
if !p.Config.SkipCleanup { |
|
|
|
|
|
commands = append(commands, deleteCache(terraformDataDir)) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
for _, c := range commands { |
|
|
for _, c := range commands { |
|
|
if c.Dir == "" { |
|
|
if c.Dir == "" { |
|
@ -331,6 +348,48 @@ func tfPlan(config Config, destroy bool) *exec.Cmd { |
|
|
) |
|
|
) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func tfSummary(config Config) *exec.Cmd { |
|
|
|
|
|
json_cmd := exec.Command("terraform", "show", "-json", getTfoutPath()) |
|
|
|
|
|
json_path := fmt.Sprintf("%s.json", getTfoutPath()) |
|
|
|
|
|
|
|
|
|
|
|
json_file, err := os.Create(json_path) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
logrus.WithFields(logrus.Fields{ |
|
|
|
|
|
"error": err, |
|
|
|
|
|
}).Fatal("Failed to create JSON state file") |
|
|
|
|
|
} |
|
|
|
|
|
logrus.Debug("JSON state file created successfully") |
|
|
|
|
|
|
|
|
|
|
|
json_cmd.Stdout = json_file |
|
|
|
|
|
defer json_file.Close() |
|
|
|
|
|
|
|
|
|
|
|
err = json_cmd.Run() |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
logrus.WithFields(logrus.Fields{ |
|
|
|
|
|
"error": err, |
|
|
|
|
|
}).Fatal("Failed to execute a command") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var args []string |
|
|
|
|
|
|
|
|
|
|
|
if config.SummarizeOptions.Draw != nil { |
|
|
|
|
|
args = append(args, "-draw") |
|
|
|
|
|
} |
|
|
|
|
|
if config.SummarizeOptions.Md != nil { |
|
|
|
|
|
args = append(args, "-md") |
|
|
|
|
|
} |
|
|
|
|
|
if config.SummarizeOptions.Tree != nil { |
|
|
|
|
|
args = append(args, "-tree") |
|
|
|
|
|
} |
|
|
|
|
|
if config.SummarizeOptions.SeparateTree != nil { |
|
|
|
|
|
args = append(args, "-separate-tree") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
args = append(args, json_path) |
|
|
|
|
|
|
|
|
|
|
|
return exec.Command("tf-summarize", args...) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func tfValidate() *exec.Cmd { |
|
|
func tfValidate() *exec.Cmd { |
|
|
return exec.Command( |
|
|
return exec.Command( |
|
|
"terraform", |
|
|
"terraform", |
|
|