diff --git a/resource.go b/resource.go index 915ea07..afbb3d7 100644 --- a/resource.go +++ b/resource.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "os" "regexp" "strconv" "strings" @@ -133,10 +134,16 @@ func (r Resource) NameWithCounter() string { // Address returns the IP address of this resource. func (r Resource) Address() string { - for _, key := range keyNames { - if ip := r.State.Primary.Attributes[key]; ip != "" { + if keyName := os.Getenv("TF_KEY_NAME"); keyName != "" { + if ip := r.State.Primary.Attributes[keyName]; ip != "" { return ip } + } else { + for _, key := range keyNames { + if ip := r.State.Primary.Attributes[key]; ip != "" { + return ip + } + } } return ""