Skip to content

Commit

Permalink
Use any for module inputs that have no type
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanck committed Nov 2, 2023
1 parent 494069b commit c7efbd7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
11 changes: 6 additions & 5 deletions schema/module_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ func schemaForDeclaredDependentModuleBlock(module module.DeclaredModuleCall, mod
}

typ := input.Type
defaultType := input.Default.Type()
if typ == cty.DynamicPseudoType && (defaultType != cty.DynamicPseudoType && defaultType != cty.NilType) {
typ = defaultType
if typ == cty.NilType {
typ = cty.DynamicPseudoType
}

aSchema.Constraint = convertAttributeTypeToConstraint(typ)

attributes[input.Name] = aSchema
Expand Down Expand Up @@ -111,8 +109,11 @@ func schemaForDependentModuleBlock(module module.InstalledModuleCall, modMeta *m
attributes := make(map[string]*schema.AttributeSchema, 0)

for name, modVar := range modMeta.Variables {
aSchema := moduleVarToAttribute(modVar)
varType := modVar.Type
if varType == cty.NilType {
varType = cty.DynamicPseudoType
}
aSchema := moduleVarToAttribute(modVar)
aSchema.Constraint = convertAttributeTypeToConstraint(varType)
aSchema.OriginForTarget = &schema.PathTarget{
Address: schema.Address{
Expand Down
6 changes: 3 additions & 3 deletions schema/module_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestSchemaForDependentModuleBlock_basic(t *testing.T) {
},
},
"another_var": {
Constraint: schema.AnyExpression{OfType: cty.String},
Constraint: schema.AnyExpression{OfType: cty.DynamicPseudoType},
IsOptional: true,
OriginForTarget: &schema.PathTarget{
Address: schema.Address{
Expand All @@ -117,7 +117,7 @@ func TestSchemaForDependentModuleBlock_basic(t *testing.T) {
},
Constraints: schema.Constraints{
ScopeId: "variable",
Type: cty.String,
Type: cty.DynamicPseudoType,
},
},
},
Expand Down Expand Up @@ -512,7 +512,7 @@ func TestSchemaForDeclaredDependentModuleBlock_basic(t *testing.T) {
IsRequired: true,
},
"foo_var": {
Constraint: schema.AnyExpression{OfType: cty.Number},
Constraint: schema.AnyExpression{OfType: cty.DynamicPseudoType},
IsOptional: true,
},
"another_var": {
Expand Down

0 comments on commit c7efbd7

Please sign in to comment.