Merge pull request #10646 from hashicorp/b-old-map

terraform: user friendly error when using old map overrides
This commit is contained in:
Mitchell Hashimoto 2016-12-12 10:51:26 -08:00 committed by GitHub
commit 8fa471d962
4 changed files with 40 additions and 1 deletions

View File

@ -44,6 +44,28 @@ func TestContext2Validate_badVar(t *testing.T) {
}
}
func TestContext2Validate_varMapOverrideOld(t *testing.T) {
m := testModule(t, "validate-module-pc-vars")
p := testProvider("aws")
c := testContext2(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
Variables: map[string]interface{}{
"foo.foo": "bar",
},
})
w, e := c.Validate()
if len(w) > 0 {
t.Fatalf("bad: %#v", w)
}
if len(e) == 0 {
t.Fatalf("bad: %s", e)
}
}
func TestContext2Validate_varNoDefaultExplicitType(t *testing.T) {
m := testModule(t, "validate-var-no-default-explicit-type")
c := testContext2(t, &ContextOpts{

View File

@ -2,6 +2,7 @@ package terraform
import (
"fmt"
"strings"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform/config"
@ -96,6 +97,21 @@ func smcUserVariables(c *config.Config, vs map[string]interface{}) []error {
// Check that types match up
for name, proposedValue := range vs {
// Check for "map.key" fields. These stopped working with Terraform
// 0.7 but we do this to surface a better error message informing
// the user what happened.
if idx := strings.Index(name, "."); idx > 0 {
key := name[:idx]
if _, ok := cvs[key]; ok {
errs = append(errs, fmt.Errorf(
"%s: Overriding map keys with the format `name.key` is no "+
"longer allowed. You may still override keys by setting "+
"`name = { key = value }`. The maps will be merged. This "+
"behavior appeared in 0.7.0.", name))
continue
}
}
schema, ok := cvs[name]
if !ok {
continue

View File

@ -24,7 +24,7 @@ func TestSMCUserVariables(t *testing.T) {
"foo": "bar",
"map.foo": "baz",
})
if len(errs) != 0 {
if len(errs) == 0 {
t.Fatalf("err: %#v", errs)
}

View File

@ -0,0 +1 @@
variable "foo" { default = { foo = "bar" } }