mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Merge branch 'jbardin/GH-7139'
This commit is contained in:
commit
ad27dc94fd
@ -2,6 +2,7 @@ package terraform
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/config"
|
"github.com/hashicorp/terraform/config"
|
||||||
@ -72,24 +73,24 @@ func (n *EvalTypeCheckVariable) Eval(ctx EvalContext) (interface{}, error) {
|
|||||||
case string:
|
case string:
|
||||||
continue
|
continue
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("variable %s%s should be type %s, got %T",
|
return nil, fmt.Errorf("variable %s%s should be type %s, got %s",
|
||||||
name, modulePathDescription, declaredType.Printable(), proposedValue)
|
name, modulePathDescription, declaredType.Printable(), hclTypeName(proposedValue))
|
||||||
}
|
}
|
||||||
case config.VariableTypeMap:
|
case config.VariableTypeMap:
|
||||||
switch proposedValue.(type) {
|
switch proposedValue.(type) {
|
||||||
case map[string]interface{}:
|
case map[string]interface{}:
|
||||||
continue
|
continue
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("variable %s%s should be type %s, got %T",
|
return nil, fmt.Errorf("variable %s%s should be type %s, got %s",
|
||||||
name, modulePathDescription, declaredType.Printable(), proposedValue)
|
name, modulePathDescription, declaredType.Printable(), hclTypeName(proposedValue))
|
||||||
}
|
}
|
||||||
case config.VariableTypeList:
|
case config.VariableTypeList:
|
||||||
switch proposedValue.(type) {
|
switch proposedValue.(type) {
|
||||||
case []interface{}:
|
case []interface{}:
|
||||||
continue
|
continue
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("variable %s%s should be type %s, got %T",
|
return nil, fmt.Errorf("variable %s%s should be type %s, got %s",
|
||||||
name, modulePathDescription, declaredType.Printable(), proposedValue)
|
name, modulePathDescription, declaredType.Printable(), hclTypeName(proposedValue))
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
// This will need the actual type substituting when we have more than
|
// This will need the actual type substituting when we have more than
|
||||||
@ -161,3 +162,26 @@ func (n *EvalVariableBlock) Eval(ctx EvalContext) (interface{}, error) {
|
|||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// hclTypeName returns the name of the type that would represent this value in
|
||||||
|
// a config file, or falls back to the Go type name if there's no corresponding
|
||||||
|
// HCL type. This is used for formatted output, not for comparing types.
|
||||||
|
func hclTypeName(i interface{}) string {
|
||||||
|
switch k := reflect.Indirect(reflect.ValueOf(i)).Kind(); k {
|
||||||
|
case reflect.Bool:
|
||||||
|
return "boolean"
|
||||||
|
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
||||||
|
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32,
|
||||||
|
reflect.Uint64, reflect.Uintptr, reflect.Float32, reflect.Float64:
|
||||||
|
return "number"
|
||||||
|
case reflect.Array, reflect.Slice:
|
||||||
|
return "list"
|
||||||
|
case reflect.Map:
|
||||||
|
return "map"
|
||||||
|
case reflect.String:
|
||||||
|
return "string"
|
||||||
|
default:
|
||||||
|
// fall back to the Go type if there's no match
|
||||||
|
return k.String()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user