|
|
|
|
@ -163,45 +163,120 @@ func TestVariables(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestSMCUserVariables(t *testing.T) {
|
|
|
|
|
c := testModule(t, "smc-uservars")
|
|
|
|
|
func TestCheckInputVariables(t *testing.T) {
|
|
|
|
|
c := testModule(t, "input-variables")
|
|
|
|
|
|
|
|
|
|
// No variables set
|
|
|
|
|
diags := checkInputVariables(c.Module.Variables, nil)
|
|
|
|
|
if !diags.HasErrors() {
|
|
|
|
|
t.Fatal("check succeeded, but want errors")
|
|
|
|
|
}
|
|
|
|
|
t.Run("No variables set", func(t *testing.T) {
|
|
|
|
|
// No variables set
|
|
|
|
|
diags := checkInputVariables(c.Module.Variables, nil)
|
|
|
|
|
if !diags.HasErrors() {
|
|
|
|
|
t.Fatal("check succeeded, but want errors")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Required variables set, optional variables unset
|
|
|
|
|
// This is still an error at this layer, since it's the caller's
|
|
|
|
|
// responsibility to have already merged in any default values.
|
|
|
|
|
diags = checkInputVariables(c.Module.Variables, InputValues{
|
|
|
|
|
"foo": &InputValue{
|
|
|
|
|
Value: cty.StringVal("bar"),
|
|
|
|
|
SourceType: ValueFromCLIArg,
|
|
|
|
|
},
|
|
|
|
|
// Required variables set, optional variables unset
|
|
|
|
|
// This is still an error at this layer, since it's the caller's
|
|
|
|
|
// responsibility to have already merged in any default values.
|
|
|
|
|
diags = checkInputVariables(c.Module.Variables, InputValues{
|
|
|
|
|
"foo": &InputValue{
|
|
|
|
|
Value: cty.StringVal("bar"),
|
|
|
|
|
SourceType: ValueFromCLIArg,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
if !diags.HasErrors() {
|
|
|
|
|
t.Fatal("check succeeded, but want errors")
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
if !diags.HasErrors() {
|
|
|
|
|
t.Fatal("check succeeded, but want errors")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// All variables set
|
|
|
|
|
diags = checkInputVariables(c.Module.Variables, InputValues{
|
|
|
|
|
"foo": &InputValue{
|
|
|
|
|
Value: cty.StringVal("bar"),
|
|
|
|
|
SourceType: ValueFromCLIArg,
|
|
|
|
|
},
|
|
|
|
|
"bar": &InputValue{
|
|
|
|
|
Value: cty.StringVal("baz"),
|
|
|
|
|
SourceType: ValueFromCLIArg,
|
|
|
|
|
},
|
|
|
|
|
"map": &InputValue{
|
|
|
|
|
Value: cty.StringVal("baz"), // okay because config has no type constraint
|
|
|
|
|
SourceType: ValueFromCLIArg,
|
|
|
|
|
},
|
|
|
|
|
t.Run("All variables set", func(t *testing.T) {
|
|
|
|
|
diags := checkInputVariables(c.Module.Variables, InputValues{
|
|
|
|
|
"foo": &InputValue{
|
|
|
|
|
Value: cty.StringVal("bar"),
|
|
|
|
|
SourceType: ValueFromCLIArg,
|
|
|
|
|
},
|
|
|
|
|
"bar": &InputValue{
|
|
|
|
|
Value: cty.StringVal("baz"),
|
|
|
|
|
SourceType: ValueFromCLIArg,
|
|
|
|
|
},
|
|
|
|
|
"map": &InputValue{
|
|
|
|
|
Value: cty.StringVal("baz"), // okay because config has no type constraint
|
|
|
|
|
SourceType: ValueFromCLIArg,
|
|
|
|
|
},
|
|
|
|
|
"object_map": &InputValue{
|
|
|
|
|
Value: cty.MapVal(map[string]cty.Value{
|
|
|
|
|
"uno": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"foo": cty.StringVal("baz"),
|
|
|
|
|
"bar": cty.NumberIntVal(2), // type = any
|
|
|
|
|
}),
|
|
|
|
|
"dos": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"foo": cty.StringVal("bat"),
|
|
|
|
|
"bar": cty.NumberIntVal(99), // type = any
|
|
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
SourceType: ValueFromCLIArg,
|
|
|
|
|
},
|
|
|
|
|
"object_list": &InputValue{
|
|
|
|
|
Value: cty.ListVal([]cty.Value{
|
|
|
|
|
cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"foo": cty.StringVal("baz"),
|
|
|
|
|
"bar": cty.NumberIntVal(2), // type = any
|
|
|
|
|
}),
|
|
|
|
|
cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"foo": cty.StringVal("bang"),
|
|
|
|
|
"bar": cty.NumberIntVal(42), // type = any
|
|
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
SourceType: ValueFromCLIArg,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
if diags.HasErrors() {
|
|
|
|
|
t.Fatalf("unexpected errors: %s", diags.Err())
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("Invalid Complex Types", func(t *testing.T) {
|
|
|
|
|
diags := checkInputVariables(c.Module.Variables, InputValues{
|
|
|
|
|
"foo": &InputValue{
|
|
|
|
|
Value: cty.StringVal("bar"),
|
|
|
|
|
SourceType: ValueFromCLIArg,
|
|
|
|
|
},
|
|
|
|
|
"bar": &InputValue{
|
|
|
|
|
Value: cty.StringVal("baz"),
|
|
|
|
|
SourceType: ValueFromCLIArg,
|
|
|
|
|
},
|
|
|
|
|
"map": &InputValue{
|
|
|
|
|
Value: cty.StringVal("baz"), // okay because config has no type constraint
|
|
|
|
|
SourceType: ValueFromCLIArg,
|
|
|
|
|
},
|
|
|
|
|
"object_map": &InputValue{
|
|
|
|
|
Value: cty.MapVal(map[string]cty.Value{
|
|
|
|
|
"uno": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"foo": cty.StringVal("baz"),
|
|
|
|
|
"bar": cty.NumberIntVal(2), // type = any
|
|
|
|
|
}),
|
|
|
|
|
"dos": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"foo": cty.StringVal("bat"),
|
|
|
|
|
"bar": cty.NumberIntVal(99), // type = any
|
|
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
SourceType: ValueFromCLIArg,
|
|
|
|
|
},
|
|
|
|
|
"object_list": &InputValue{
|
|
|
|
|
Value: cty.TupleVal([]cty.Value{
|
|
|
|
|
cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"foo": cty.StringVal("baz"),
|
|
|
|
|
"bar": cty.NumberIntVal(2), // type = any
|
|
|
|
|
}),
|
|
|
|
|
cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"foo": cty.StringVal("bang"),
|
|
|
|
|
"bar": cty.StringVal("42"), // type = any, but mismatch with the first list item
|
|
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
SourceType: ValueFromCLIArg,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if diags.HasErrors() {
|
|
|
|
|
t.Fatalf("unexpected errors: %s", diags.Err())
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
if diags.HasErrors() {
|
|
|
|
|
//t.Fatal("check succeeded, but want errors")
|
|
|
|
|
t.Fatalf("unexpected errors: %s", diags.Err())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|