From 7ccb21d864f0966ff2de02e6584a9eba52b0e4e5 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 3 Jan 2024 09:14:11 -0500 Subject: [PATCH] Block.Filter can panic with no attrs Make sure that we only dereference an attribute is it was set in the filter. While not extremely useful, a provider could have a nested object with no attributes. --- internal/configs/configschema/filter.go | 7 +++---- internal/configs/configschema/filter_test.go | 6 ++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/internal/configs/configschema/filter.go b/internal/configs/configschema/filter.go index f4697d2f20..35aeba714c 100644 --- a/internal/configs/configschema/filter.go +++ b/internal/configs/configschema/filter.go @@ -50,10 +50,9 @@ func (b *Block) Filter(filterAttribute FilterT[*Attribute], filterBlock FilterT[ for name, attrS := range b.Attributes { if filterAttribute == nil || !filterAttribute(name, attrS) { ret.Attributes[name] = attrS - } - - if attrS.NestedType != nil { - ret.Attributes[name].NestedType = filterNestedType(attrS.NestedType, filterAttribute) + if attrS.NestedType != nil { + ret.Attributes[name].NestedType = filterNestedType(attrS.NestedType, filterAttribute) + } } } diff --git a/internal/configs/configschema/filter_test.go b/internal/configs/configschema/filter_test.go index 6525a565d2..b2666f0a40 100644 --- a/internal/configs/configschema/filter_test.go +++ b/internal/configs/configschema/filter_test.go @@ -175,6 +175,12 @@ func TestFilter(t *testing.T) { Nesting: NestingList, }, }, + "missing_attributes": { + NestedType: &Object{ + Nesting: NestingList, + }, + Computed: true, + }, }, BlockTypes: map[string]*NestedBlock{