mirror of
https://github.com/adammck/terraform-inventory
synced 2024-11-23 00:12:13 +01:00
Merge pull request #28 from anarcher/master
Add ENV TERRAFORM_INVENTORY_KEYNAME to specify which IP to return
This commit is contained in:
commit
35e77604ba
11
resource.go
11
resource.go
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -133,10 +134,16 @@ func (r Resource) NameWithCounter() string {
|
|||||||
|
|
||||||
// Address returns the IP address of this resource.
|
// Address returns the IP address of this resource.
|
||||||
func (r Resource) Address() string {
|
func (r Resource) Address() string {
|
||||||
for _, key := range keyNames {
|
if keyName := os.Getenv("TF_KEY_NAME"); keyName != "" {
|
||||||
if ip := r.State.Primary.Attributes[key]; ip != "" {
|
if ip := r.State.Primary.Attributes[keyName]; ip != "" {
|
||||||
return ip
|
return ip
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
for _, key := range keyNames {
|
||||||
|
if ip := r.State.Primary.Attributes[key]; ip != "" {
|
||||||
|
return ip
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
Loading…
Reference in New Issue
Block a user