Skip to content

Commit

Permalink
local target range match fix
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Nov 15, 2022
1 parent d1933e8 commit 54af013
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 5 additions & 5 deletions reference/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,12 @@ func (target Target) Matches(origin MatchableOrigin) bool {
}
}

// Reject origin if it's outside the targetable range
// TODO! this should only apply when dealing with LocalAddr
// this currently rejects valid matches targeting an attribute from an output block
// If the target is only targetable from a particular range
// we confirm that the origin is within that range.
targetRangeMatches := true
if target.TargetableFromRangePtr != nil && !rangeOverlaps(*target.TargetableFromRangePtr, origin.OriginRange()) {
return false
targetRangeMatches = false
}

return (target.LocalAddr.Equals(localOriginAddr) || target.Addr.Equals(originAddr)) && matchesCons
return ((target.LocalAddr.Equals(localOriginAddr) && targetRangeMatches) || target.Addr.Equals(originAddr)) && matchesCons
}
10 changes: 10 additions & 0 deletions reference/targets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ func TestTargets_Match(t *testing.T) {
lang.AttrStep{Name: "foo"},
lang.AttrStep{Name: "signing_algorithm"},
},

Constraints: OriginConstraints{
{OfType: cty.DynamicPseudoType},
},
Expand All @@ -251,7 +252,16 @@ func TestTargets_Match(t *testing.T) {
lang.AttrStep{Name: "foo"},
lang.AttrStep{Name: "signing_algorithm"},
},
LocalAddr: lang.Address{
lang.RootStep{Name: "self"},
lang.AttrStep{Name: "signing_algorithm"},
},
Type: cty.String,
TargetableFromRangePtr: &hcl.Range{
Filename: "main.tf",
Start: hcl.Pos{Line: 26, Column: 41, Byte: 360},
End: hcl.Pos{Line: 41, Column: 2, Byte: 657},
},
},
},
true,
Expand Down

0 comments on commit 54af013

Please sign in to comment.