mirror of
https://github.com/adammck/terraform-inventory
synced 2024-11-23 04:22:08 +01:00
36 lines
463 B
Go
36 lines
463 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"github.com/adammck/venv"
|
||
|
"github.com/blang/vfs"
|
||
|
)
|
||
|
|
||
|
func GetInputPath(fs vfs.Filesystem, env venv.Env) string {
|
||
|
|
||
|
var fn string
|
||
|
|
||
|
fn = env.Getenv("TF_STATE")
|
||
|
if fn != "" {
|
||
|
return fn
|
||
|
}
|
||
|
|
||
|
fn = env.Getenv("TI_TFSTATE")
|
||
|
if fn != "" {
|
||
|
return fn
|
||
|
}
|
||
|
|
||
|
fn = "terraform.tfstate"
|
||
|
_, err := fs.Stat(fn)
|
||
|
if err == nil {
|
||
|
return fn
|
||
|
}
|
||
|
|
||
|
fn = ".terraform/terraform.tfstate"
|
||
|
_, err = fs.Stat(fn)
|
||
|
if err == nil {
|
||
|
return fn
|
||
|
}
|
||
|
|
||
|
return ""
|
||
|
}
|