mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-30 10:47:14 -06:00
808f09f01f
Related to #8036 We have had this behavior for a _long_ time now (since 0.7.0) but it seems people are still periodically getting bit by it. This adds an explicit error message that explains that this kind of override isn't allowed anymore.
58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
package terraform
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestSMCUserVariables(t *testing.T) {
|
|
c := testConfig(t, "smc-uservars")
|
|
|
|
// Required variables not set
|
|
errs := smcUserVariables(c, nil)
|
|
if len(errs) == 0 {
|
|
t.Fatal("should have errors")
|
|
}
|
|
|
|
// Required variables set, optional variables unset
|
|
errs = smcUserVariables(c, map[string]interface{}{"foo": "bar"})
|
|
if len(errs) != 0 {
|
|
t.Fatalf("err: %#v", errs)
|
|
}
|
|
|
|
// Mapping element override
|
|
errs = smcUserVariables(c, map[string]interface{}{
|
|
"foo": "bar",
|
|
"map.foo": "baz",
|
|
})
|
|
if len(errs) == 0 {
|
|
t.Fatalf("err: %#v", errs)
|
|
}
|
|
|
|
// Mapping complete override
|
|
errs = smcUserVariables(c, map[string]interface{}{
|
|
"foo": "bar",
|
|
"map": "baz",
|
|
})
|
|
if len(errs) == 0 {
|
|
t.Fatal("should have errors")
|
|
}
|
|
|
|
}
|
|
|
|
func TestSMCUserVariables_mapFromJSON(t *testing.T) {
|
|
c := testConfig(t, "uservars-map")
|
|
|
|
// ensure that a single map in a list can satisfy a map variable, since it
|
|
// will be coerced later to a map
|
|
err := smcUserVariables(c, map[string]interface{}{
|
|
"test_map": []map[string]interface{}{
|
|
map[string]interface{}{
|
|
"foo": "bar",
|
|
},
|
|
},
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|