mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
core: Do not type check unset variables
A consequnce of the work done in #6185 was that variables which were in a module but not set explicitly (i.e. the default value was relied upon) were marked as type errors. This was reported in #6230. This commit adds a test case for this and a patch which fixes the issue.
This commit is contained in:
parent
dcf0996015
commit
31cc2d2ccd
@ -660,6 +660,23 @@ func TestContext2Plan_moduleVarWrongTypeNested(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext2Plan_moduleVarWithDefaultValue(t *testing.T) {
|
||||
m := testModule(t, "plan-module-var-with-default-value")
|
||||
p := testProvider("null")
|
||||
p.DiffFn = testDiffFn
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"null": testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
_, err := ctx.Plan()
|
||||
if err != nil {
|
||||
t.Fatalf("bad: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext2Plan_moduleVarComputed(t *testing.T) {
|
||||
m := testModule(t, "plan-module-var-computed")
|
||||
p := testProvider("aws")
|
||||
|
@ -48,7 +48,12 @@ func (n *EvalTypeCheckVariable) Eval(ctx EvalContext) (interface{}, error) {
|
||||
// that at the current time we are dealing with a type system consisting only
|
||||
// of strings and maps - where the only valid inter-module variable type is
|
||||
// string.
|
||||
// proposedValue := n.Variables[name]
|
||||
_, ok := n.Variables[name]
|
||||
if !ok {
|
||||
// This means the default value should be used as no overriding value
|
||||
// has been set. Therefore we should continue as no check is necessary.
|
||||
continue
|
||||
}
|
||||
|
||||
switch declaredType {
|
||||
case config.VariableTypeString:
|
||||
|
@ -0,0 +1,12 @@
|
||||
variable "im_a_string" {
|
||||
type = "string"
|
||||
}
|
||||
|
||||
variable "service_region_ami" {
|
||||
type = "map"
|
||||
default = {
|
||||
us-east-1 = "ami-e4c9db8e"
|
||||
}
|
||||
}
|
||||
|
||||
resource "null_resource" "noop" {}
|
@ -0,0 +1,7 @@
|
||||
resource "null_resource" "noop" {}
|
||||
|
||||
module "test" {
|
||||
source = "./inner"
|
||||
|
||||
im_a_string = "hello"
|
||||
}
|
Loading…
Reference in New Issue
Block a user