Skip to content

Commit

Permalink
moved show related code
Browse files Browse the repository at this point in the history
  • Loading branch information
mkyc committed Nov 25, 2020
1 parent 9acd991 commit 200c048
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ func main() {
opts, err := terra.WithDefaultRetryableErrors(&terra.Options{
TerraformDir: "./tests",
StateFilePath: "./subdir/other-state.tfstate",
PlanFilePath: "./subdir/other-plan.tfplan",
})
if err != nil {
panic(err)
Expand Down Expand Up @@ -38,6 +39,18 @@ func main() {
}
println(s)

println("===============")
println("===============")
println("=== show ======")
println("===============")
println("===============")

s, err = terra.Show(opts)
if err != nil {
panic(err)
}
println(s)

println("===============")
println("===============")
println("=== apply =====")
Expand Down
16 changes: 16 additions & 0 deletions show.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package terra

// Show calls terraform show in json mode with the given options and returns stdout from the command. If
// PlanFilePath is set on the options, this will show the plan file. Otherwise, this will show the current state of the
// terraform module at options.TerraformDir. This will fail the test if there is an error in the command.
func Show(options *Options) (string, error) {
// We manually construct the args here instead of using `FormatArgs`, because show only accepts a limited set of
// args.
args := []string{"show", "-no-color", "-json"}

// Attach plan file path if specified.
if options.PlanFilePath != "" {
args = append(args, options.PlanFilePath)
}
return RunTerraformCommandAndGetStdoutE(options, args...)
}

0 comments on commit 200c048

Please sign in to comment.