diff --git a/resources/iot-thinggroups.go b/resources/iot-thinggroups.go index e4942393..70594131 100644 --- a/resources/iot-thinggroups.go +++ b/resources/iot-thinggroups.go @@ -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" ) @@ -57,10 +58,16 @@ 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, }) } @@ -68,12 +75,22 @@ func (l *IoTThingGroupLister) List(_ context.Context, o interface{}) ([]resource } 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, @@ -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 +}