command: validate backend config

The validation itself was added a couple weeks ago but I forgot to
actually call it. :sad:
This commit is contained in:
Mitchell Hashimoto 2017-03-02 14:07:49 -08:00
parent a2d78b62aa
commit 03493f7d46
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
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) 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 the configuration which may or may not be set
return backend, nil 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 // Newly configured backend
func TestMetaBackend_configureNew(t *testing.T) { func TestMetaBackend_configureNew(t *testing.T) {
// Create a temporary working directory that is empty // Create a temporary working directory that is empty

View File

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