Skip to content

Commit

Permalink
Decouple Terraform version resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Oct 10, 2023
1 parent baf127c commit b5e040a
Showing 1 changed file with 3 additions and 26 deletions.
29 changes: 3 additions & 26 deletions internal/decoder/module_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import (
)

func schemaForModule(mod *state.Module, schemaReader state.SchemaReader, modReader state.ModuleCallReader) (*schema.BodySchema, error) {
sm := tfschema.NewSchemaMerger(coreSchema(mod))
resolvedVersion := tfschema.ResolveVersion(mod.TerraformVersion, mod.Meta.CoreRequirements)
sm := tfschema.NewSchemaMerger(mustCoreSchemaForVersion(resolvedVersion))
sm.SetSchemaReader(schemaReader)
sm.SetTerraformVersion(mod.TerraformVersion)
sm.SetTerraformVersion(resolvedVersion)
sm.SetModuleReader(modReader)

meta := &tfmodule.Meta{
Expand All @@ -30,30 +31,6 @@ func schemaForModule(mod *state.Module, schemaReader state.SchemaReader, modRead
return sm.SchemaForModule(meta)
}

func coreSchema(mod *state.Module) *schema.BodySchema {
if mod.TerraformVersion != nil {
s, err := tfschema.CoreModuleSchemaForVersion(mod.TerraformVersion)
if err == nil {
return s
}
if mod.TerraformVersion.LessThan(tfschema.OldestAvailableVersion) {
return mustCoreSchemaForVersion(tfschema.OldestAvailableVersion)
}

return mustCoreSchemaForVersion(tfschema.LatestAvailableVersion)
}

s, err := tfschema.CoreModuleSchemaForConstraint(mod.Meta.CoreRequirements)
if err == nil {
return s
}
if mod.Meta.CoreRequirements.Check(tfschema.OldestAvailableVersion) {
return mustCoreSchemaForVersion(tfschema.OldestAvailableVersion)
}

return mustCoreSchemaForVersion(tfschema.LatestAvailableVersion)
}

func mustCoreSchemaForVersion(v *version.Version) *schema.BodySchema {
s, err := tfschema.CoreModuleSchemaForVersion(v)
if err != nil {
Expand Down

0 comments on commit b5e040a

Please sign in to comment.