Skip to content

Commit

Permalink
efactor functions merger
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanck committed Apr 10, 2024
1 parent d3a4762 commit 418dec0
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions schema/functions_merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
type FunctionsMerger struct {
coreFunctions map[string]schema.FunctionSignature
terraformVersion *version.Version
schemaReader SchemaReader
stateReader StateReader
}

func NewFunctionsMerger(coreFunctions map[string]schema.FunctionSignature) *FunctionsMerger {
Expand All @@ -23,8 +23,8 @@ func NewFunctionsMerger(coreFunctions map[string]schema.FunctionSignature) *Func
}
}

func (m *FunctionsMerger) SetSchemaReader(sr SchemaReader) {
m.schemaReader = sr
func (m *FunctionsMerger) SetStateReader(mr StateReader) {
m.stateReader = mr
}

func (m *FunctionsMerger) SetTerraformVersion(v *version.Version) {
Expand All @@ -51,19 +51,17 @@ func (m *FunctionsMerger) FunctionsForModule(meta *tfmod.Meta) (map[string]schem

providerRefs := ProviderReferences(meta.ProviderReferences)

if m.schemaReader != nil {
for pAddr, pVersionCons := range meta.ProviderRequirements {
pSchema, err := m.schemaReader.ProviderSchema(meta.Path, pAddr, pVersionCons)
if err != nil {
continue
}
for pAddr, pVersionCons := range meta.ProviderRequirements {
pSchema, err := m.stateReader.ProviderSchema(meta.Path, pAddr, pVersionCons)
if err != nil {
continue
}

refs := providerRefs.ReferencesOfProvider(pAddr)
refs := providerRefs.ReferencesOfProvider(pAddr)

for _, localRef := range refs {
for fName, fSig := range pSchema.Functions {
mergedFunctions[fmt.Sprintf("provider::%s::%s", localRef.LocalName, fName)] = *fSig.Copy()
}
for _, localRef := range refs {
for fName, fSig := range pSchema.Functions {
mergedFunctions[fmt.Sprintf("provider::%s::%s", localRef.LocalName, fName)] = *fSig.Copy()
}
}
}
Expand Down

0 comments on commit 418dec0

Please sign in to comment.