Merge pull request #10646 from hashicorp/b-old-map
terraform: user friendly error when using old map overrides
This commit is contained in:
commit
8fa471d962
|
@ -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) {
|
func TestContext2Validate_varNoDefaultExplicitType(t *testing.T) {
|
||||||
m := testModule(t, "validate-var-no-default-explicit-type")
|
m := testModule(t, "validate-var-no-default-explicit-type")
|
||||||
c := testContext2(t, &ContextOpts{
|
c := testContext2(t, &ContextOpts{
|
||||||
|
|
|
@ -2,6 +2,7 @@ package terraform
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/go-multierror"
|
"github.com/hashicorp/go-multierror"
|
||||||
"github.com/hashicorp/terraform/config"
|
"github.com/hashicorp/terraform/config"
|
||||||
|
@ -96,6 +97,21 @@ func smcUserVariables(c *config.Config, vs map[string]interface{}) []error {
|
||||||
|
|
||||||
// Check that types match up
|
// Check that types match up
|
||||||
for name, proposedValue := range vs {
|
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]
|
schema, ok := cvs[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -24,7 +24,7 @@ func TestSMCUserVariables(t *testing.T) {
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
"map.foo": "baz",
|
"map.foo": "baz",
|
||||||
})
|
})
|
||||||
if len(errs) != 0 {
|
if len(errs) == 0 {
|
||||||
t.Fatalf("err: %#v", errs)
|
t.Fatalf("err: %#v", errs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
variable "foo" { default = { foo = "bar" } }
|
Loading…
Reference in New Issue