From dbe88863eb52a5f05b78dad216eaf11864e0a1a8 Mon Sep 17 00:00:00 2001 From: Adam Mckaig Date: Fri, 5 Jun 2015 00:22:08 -0400 Subject: [PATCH] Also check for terraform.tfstate in pwd --- main.go | 9 +++++++++ parser.go | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 46d183f..2294a22 100644 --- a/main.go +++ b/main.go @@ -30,6 +30,15 @@ func main() { file = os.Getenv("TI_TFSTATE") } + // check for a file named terraform.tfstate in the pwd + if file == "" { + fn := "terraform.tfstate" + _, err := os.Stat(fn) + if err == nil { + file = fn + } + } + if file == "" { fmt.Printf("Usage: %s [options] path\n", os.Args[0]) os.Exit(1) diff --git a/parser.go b/parser.go index 1b6196c..85cbf90 100644 --- a/parser.go +++ b/parser.go @@ -19,8 +19,8 @@ var keyNames []string func init() { keyNames = []string{ "ipv4_address", // DO - "public_ip", // AWS - "private_ip", // AWS + "public_ip", // AWS + "private_ip", // AWS } } @@ -76,7 +76,7 @@ func (s resourceState) isSupported() bool { // Address returns the IP address of this resource. func (s resourceState) Address() string { - for _, key := range(keyNames) { + for _, key := range keyNames { if ip := s.Primary.Attributes[key]; ip != "" { return ip }