Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(iot-thinggroups): support deleting dynamic thing groups #124

Merged
merged 2 commits into from
Mar 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions resources/iot-thinggroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/ekristen/libnuke/pkg/registry"
"github.com/ekristen/libnuke/pkg/resource"
"github.com/ekristen/libnuke/pkg/types"

"github.com/ekristen/aws-nuke/pkg/nuke"
)
Expand Down Expand Up @@ -57,23 +58,39 @@ func (l *IoTThingGroupLister) List(_ context.Context, o interface{}) ([]resource
return nil, err
}

thingGroupType := "static"
if output.IndexName != nil {
thingGroupType = "dynamic"
}

resources = append(resources, &IoTThingGroup{
svc: svc,
name: thingGroup.GroupName,
version: output.Version,
svc: svc,
name: thingGroup.GroupName,
version: output.Version,
groupType: thingGroupType,
})
}

return resources, nil
}

type IoTThingGroup struct {
svc *iot.IoT
name *string
version *int64
svc *iot.IoT
name *string
version *int64
groupType string
}

func (f *IoTThingGroup) Remove(_ context.Context) error {
if f.groupType == "dynamic" {
_, err := f.svc.DeleteDynamicThingGroup(&iot.DeleteDynamicThingGroupInput{
ThingGroupName: f.name,
ExpectedVersion: f.version,
})

return err
}

_, err := f.svc.DeleteThingGroup(&iot.DeleteThingGroupInput{
ThingGroupName: f.name,
ExpectedVersion: f.version,
Expand All @@ -85,3 +102,12 @@ func (f *IoTThingGroup) Remove(_ context.Context) error {
func (f *IoTThingGroup) String() string {
return *f.name
}

func (f *IoTThingGroup) Properties() types.Properties {
properties := types.NewProperties()

properties.Set("Name", f.name)
properties.Set("Type", f.groupType)

return properties
}