1
1
mirror of https://github.com/adammck/terraform-inventory synced 2024-11-23 00:12:13 +01:00

Add ENV TERRAFORM_INVENTORY_KEYNAME to specify which IP to return

This commit is contained in:
anarcher 2016-02-17 16:45:45 +09:00
parent 229202334c
commit 36d30f6d40

@ -2,6 +2,7 @@ package main
import (
"fmt"
"os"
"regexp"
"strconv"
"strings"
@ -133,11 +134,17 @@ func (r Resource) NameWithCounter() string {
// Address returns the IP address of this resource.
func (r Resource) Address() string {
if keyName := os.Getenv("TERRAFORM_INVENTORY_KEYNAME"); 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 ""
}