Skip to content

Commit b751d91

Browse files
Fix invalid input exception when updating tags (#30)
Description of changes: The IAM API will throw an `InvalidInput` exception when attempting to add or delete an empty list of tags. This pull request adds a condition to guard against this. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 8c18ddb commit b751d91

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

pkg/resource/role/hooks.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,21 @@ func (rm *resourceManager) syncTags(
166166
}
167167
}
168168

169-
for _, t := range toAdd {
170-
rlog.Debug("adding tag to role", "key", *t.Key, "value", *t.Value)
171-
}
172-
if err = rm.addTags(ctx, r, toAdd); err != nil {
173-
return err
174-
}
175-
for _, t := range toDelete {
176-
rlog.Debug("removing tag from role", "key", *t.Key, "value", *t.Value)
169+
if len(toAdd) > 0 {
170+
for _, t := range toAdd {
171+
rlog.Debug("adding tag to role", "key", *t.Key, "value", *t.Value)
172+
}
173+
if err = rm.addTags(ctx, r, toAdd); err != nil {
174+
return err
175+
}
177176
}
178-
if err = rm.removeTags(ctx, r, toDelete); err != nil {
179-
return err
177+
if len(toDelete) > 0 {
178+
for _, t := range toDelete {
179+
rlog.Debug("removing tag from role", "key", *t.Key, "value", *t.Value)
180+
}
181+
if err = rm.removeTags(ctx, r, toDelete); err != nil {
182+
return err
183+
}
180184
}
181185

182186
return nil

0 commit comments

Comments
 (0)