Last active
March 22, 2018 17:00
-
-
Save meatballhat/d644c2f75dd98cba6638c38e7a9561a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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