Skip to content

Instantly share code, notes, and snippets.

@meatballhat
Last active March 22, 2018 17:00
Show Gist options
  • Save meatballhat/d644c2f75dd98cba6638c38e7a9561a2 to your computer and use it in GitHub Desktop.
Save meatballhat/d644c2f75dd98cba6638c38e7a9561a2 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"io"
"log"
"os"
"github.com/hashicorp/terraform/terraform"
)
func main() {
stat, err := os.Stdin.Stat()
if err != nil {
log.Fatalf("Error encountered when checking stdin: %s", err)
}
if stat.Size() <= 0 {
log.Fatal("You must pass a plan file via stdin!")
}
plan, err := terraform.ReadPlan(os.Stdin)
if err != nil {
log.Fatalf("Error reading plan! %s\n\nAre you sure the plan file was passed?", err)
}
encoded, err := json.MarshalIndent(plan, "", " ")
if err != nil {
log.Fatalf("Error attempting to serialize plan to JSON! %s", err)
}
io.WriteString(os.Stdout, string(encoded))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment