Skip to content

Commit

Permalink
Add replace field for copy-instance-tags
Browse files Browse the repository at this point in the history
  • Loading branch information
HappyKid117 committed Oct 16, 2022
1 parent 5fbcedc commit af17637
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion c7n/resources/ebs.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,8 @@ class CopyInstanceTags(BaseAction):

schema = type_schema(
'copy-instance-tags',
tags={'type': 'array', 'items': {'type': 'string'}})
tags={'type': 'array', 'items': {'type': 'string'}},
replace={'type': 'boolean'})

def get_permissions(self):
perms = self.manager.get_resource_manager('ec2').get_permissions()
Expand Down Expand Up @@ -992,6 +993,7 @@ def process_instance_volumes(self, client, instance, volumes):
def get_volume_tags(self, volume, instance, attachment):
only_tags = self.data.get('tags', []) # specify which tags to copy
copy_tags = []
replace = self.data.get('replace', True)
extant_tags = dict([
(t['Key'], t['Value']) for t in volume.get('Tags', [])])

Expand All @@ -1000,6 +1002,8 @@ def get_volume_tags(self, volume, instance, attachment):
continue
if t['Key'] in extant_tags and t['Value'] == extant_tags[t['Key']]:
continue
if t['Key'] in extant_tags and not replace:
continue
if t['Key'].startswith('aws:'):
continue
copy_tags.append(t)
Expand Down

0 comments on commit af17637

Please sign in to comment.