Skip to content

Commit

Permalink
r/aws_iot_thing_group: fix crash with empty attribute_payload block
Browse files Browse the repository at this point in the history
Setting the `attribute_payload` argument to an empty block resulted the in the associated expander attempting to assert the lists single nil item into a map. This change adds a check for nil items to prevent this.

```console
% make testacc PKG=iot TESTS=TestAccIoTThingGroup_
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.22.6 test ./internal/service/iot/... -v -count 1 -parallel 20 -run='TestAccIoTThingGroup_'  -timeout 360m

--- PASS: TestAccIoTThingGroup_disappears (12.93s)
--- PASS: TestAccIoTThingGroup_basic (15.24s)
--- PASS: TestAccIoTThingGroup_parentGroup (19.73s)
--- PASS: TestAccIoTThingGroup_properties (22.78s)
--- PASS: TestAccIoTThingGroup_tags (30.27s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/iot        36.178s
```
  • Loading branch information
jar-b committed Aug 8, 2024
1 parent 0f98773 commit bbaa9f7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/38776.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_iot_thing_group: Fix crash when empty `attribute_payload` block is configured
```
2 changes: 1 addition & 1 deletion internal/service/iot/thing_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func expandThingGroupProperties(tfMap map[string]interface{}) *awstypes.ThingGro

apiObject := &awstypes.ThingGroupProperties{}

if v, ok := tfMap["attribute_payload"].([]interface{}); ok && len(v) > 0 {
if v, ok := tfMap["attribute_payload"].([]interface{}); ok && len(v) > 0 && v[0] != nil {
apiObject.AttributePayload = expandAttributePayload(v[0].(map[string]interface{}))
}

Expand Down

0 comments on commit bbaa9f7

Please sign in to comment.