remote: respect ATLAS_TOKEN

This commit is contained in:
Mitchell Hashimoto 2014-12-09 19:19:04 -08:00
parent f0de69b3c5
commit 8cb3e5715b
2 changed files with 22 additions and 1 deletions

View File

@ -8,6 +8,7 @@ import (
"io"
"net/http"
"net/url"
"os"
"path"
"strings"
)
@ -48,8 +49,13 @@ func (c *AtlasRemoteClient) validateConfig(conf map[string]string) error {
c.serverURL = url
token, ok := conf["access_token"]
if token == "" {
token = os.Getenv("ATLAS_TOKEN")
ok = true
}
if !ok || token == "" {
return fmt.Errorf("missing 'access_token' configuration")
return fmt.Errorf(
"missing 'access_token' configuration or ATLAS_TOKEN environmental variable")
}
c.accessToken = token

View File

@ -35,6 +35,21 @@ func TestAtlasRemote_Validate(t *testing.T) {
}
}
func TestAtlasRemote_Validate_envVar(t *testing.T) {
conf := map[string]string{}
if _, err := NewAtlasRemoteClient(conf); err == nil {
t.Fatalf("expect error")
}
defer os.Setenv("ATLAS_TOKEN", os.Getenv("ATLAS_TOKEN"))
os.Setenv("ATLAS_TOKEN", "foo")
conf["name"] = "hashicorp/test-state"
if _, err := NewAtlasRemoteClient(conf); err != nil {
t.Fatalf("err: %v", err)
}
}
func TestAtlasRemote(t *testing.T) {
checkAtlas(t)
remote := &terraform.RemoteState{