Merge pull request #12388 from hashicorp/b-backend-validate

command: validate backend config
This commit is contained in:
Mitchell Hashimoto 2017-03-02 14:44:44 -08:00 committed by GitHub
commit 452f47ce8c
3 changed files with 31 additions and 0 deletions

View File

@ -237,6 +237,12 @@ func (m *Meta) backendConfig(opts *BackendOpts) (*config.Backend, error) {
backend.RawConfig = backend.RawConfig.Merge(rc)
}
// Validate the backend early. We have to do this before the normal
// config validation pass since backend loading happens earlier.
if errs := backend.Validate(); len(errs) > 0 {
return nil, multierror.Append(nil, errs...)
}
// Return the configuration which may or may not be set
return backend, nil
}

View File

@ -267,6 +267,24 @@ func TestMetaBackend_emptyLegacyRemote(t *testing.T) {
}
}
// Verify that interpolations result in an error
func TestMetaBackend_configureInterpolation(t *testing.T) {
// Create a temporary working directory that is empty
td := tempDir(t)
copy.CopyDir(testFixturePath("backend-new-interp"), td)
defer os.RemoveAll(td)
defer testChdir(t, td)()
// Setup the meta
m := testMetaBackend(t, nil)
// Get the backend
_, err := m.Backend(&BackendOpts{Init: true})
if err == nil {
t.Fatal("should error")
}
}
// Newly configured backend
func TestMetaBackend_configureNew(t *testing.T) {
// Create a temporary working directory that is empty

View File

@ -0,0 +1,7 @@
variable "foo" { default = "bar" }
terraform {
backend "local" {
path = "${var.foo}"
}
}