Skip to content

Commit

Permalink
ensure set properties are loaded into eval as expected (#940)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhsinger-klotho authored Feb 27, 2024
1 parent 1d45400 commit a512937
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions pkg/construct/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,13 @@ func (r *Resource) PropertyPath(pathStr string) (PropertyPath, error) {
value = value.Elem()
}
if value.IsValid() && value.Kind() != reflect.Slice && value.Kind() != reflect.Array {
return nil, &PropertyPathError{
Path: pathParts[:i-1],
Cause: fmt.Errorf("expected array, got %s", value.Type()),
if hs, ok := value.Interface().(set.HashedSet[string, any]); ok {
value = reflect.ValueOf(hs.ToSlice())
} else {
return nil, &PropertyPathError{
Path: pathParts[:i-1],
Cause: fmt.Errorf("expected array, got %s", value.Type()),
}
}
}
if !value.IsValid() || value.IsZero() {
Expand Down
4 changes: 2 additions & 2 deletions pkg/knowledgebase/resource_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,11 @@ func (tmpl ResourceTemplate) LoopProperties(res *construct.Resource, addProp fun
errs = errors.Join(errs, fmt.Errorf("could not cast property to set"))
continue
}
for k := range hs.ToMap() {
for i := range hs.ToSlice() {
subProperties := make(Properties)
for subK, subProp := range prop.SubProperties() {
propTemplate := subProp.Clone()
ReplacePath(propTemplate, prop.Details().Path, fmt.Sprintf("%s[%s]", prop.Details().Path, k))
ReplacePath(propTemplate, prop.Details().Path, fmt.Sprintf("%s[%d]", prop.Details().Path, i))
subProperties[subK] = propTemplate
}
if len(subProperties) > 0 {
Expand Down

0 comments on commit a512937

Please sign in to comment.