Skip to content

Commit

Permalink
Fix unresolvedBlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
kaidaguerre committed Sep 19, 2023
1 parent a36dd1b commit 6744f6d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 3 additions & 3 deletions pkg/steampipeconfig/parse/parse_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (r *ParseContext) ClearDependencies() {
func (r *ParseContext) AddDependencies(block *hcl.Block, name string, dependencies map[string]*modconfig.ResourceDependency) hcl.Diagnostics {
var diags hcl.Diagnostics
// store unresolved block
r.UnresolvedBlocks[name] = &unresolvedBlock{Name: name, Block: block, Dependencies: dependencies}
r.UnresolvedBlocks[name] = newUnresolvedBlock(block, name, dependencies)

// store dependency in tree - d
if !r.dependencyGraph.ContainsNode(name) {
Expand Down Expand Up @@ -119,10 +119,10 @@ func (r *ParseContext) BlocksToDecode() (hcl.Blocks, error) {
// depOrder is all the blocks required to resolve dependencies.
// if this one is unparsed, added to list
block, ok := r.UnresolvedBlocks[name]
if !blocksMap[hclhelpers.BlockRange(block.Block).String()] && ok {
if ok && !blocksMap[block.DeclRange.String()] && ok {
blocksToDecode = append(blocksToDecode, block.Block)
// add to map
blocksMap[hclhelpers.BlockRange(block.Block).String()] = true
blocksMap[block.DeclRange.String()] = true
}
}
return blocksToDecode, nil
Expand Down
14 changes: 12 additions & 2 deletions pkg/steampipeconfig/parse/unresolved_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,27 @@ import (
"fmt"
"strings"

"github.com/turbot/steampipe/pkg/steampipeconfig/modconfig"

"github.com/hashicorp/hcl/v2"
"github.com/turbot/steampipe/pkg/steampipeconfig/hclhelpers"
"github.com/turbot/steampipe/pkg/steampipeconfig/modconfig"
)

type unresolvedBlock struct {
Name string
Block *hcl.Block
DeclRange hcl.Range
Dependencies map[string]*modconfig.ResourceDependency
}

func newUnresolvedBlock(block *hcl.Block, name string, dependencies map[string]*modconfig.ResourceDependency) *unresolvedBlock {
return &unresolvedBlock{
Name: name,
Block: block,
Dependencies: dependencies,
DeclRange: hclhelpers.BlockRange(block),
}
}

func (b unresolvedBlock) String() string {
depStrings := make([]string, len(b.Dependencies))
idx := 0
Expand Down

0 comments on commit 6744f6d

Please sign in to comment.