Skip to content
This repository was archived by the owner on Dec 29, 2021. It is now read-only.

Commit 4929258

Browse files
authored
Merge pull request #1 from Eddman/master
Fixed incorrect tag filter
2 parents 2aba306 + 5dafc0d commit 4929258

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

template/tagging_lambda.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121

2222
# Tag the resources ...
2323
def lambda_handler(event, context):
24-
filter = [{'Name':'tag:kubernetes.io/cluster/' + cluster, 'Values':['owned']}]
24+
kubeClusterTagKey = 'kubernetes.io/cluster/' + cluster
25+
kubeClusterTagValue = 'owned'
26+
filter = [{'Name':'tag:' + kubeClusterTagKey, 'Values':[kubeClusterTagValue]}]
2527

2628
ec2 = boto3.resource('ec2', region_name=region)
2729

@@ -135,7 +137,7 @@ def lambda_handler(event, context):
135137
asgs = autoscaling.describe_auto_scaling_groups(MaxRecords=100)
136138
for asg in asgs['AutoScalingGroups']:
137139
for tag in asg['Tags']:
138-
if tag['Key'] == 'KubernetesCluster' and tag['Value'] == cluster:
140+
if tag['Key'] == kubeClusterTagKey and tag['Value'] == kubeClusterTagValue:
139141
newTags = prepare_new_tags(asg['Tags'])
140142

141143
if len(newTags) > 0:
@@ -153,7 +155,7 @@ def lambda_handler(event, context):
153155
for elb in elbs['LoadBalancerDescriptions']:
154156
tags = loadbalancing.describe_tags(LoadBalancerNames=[elb['LoadBalancerName']])
155157
for tag in tags['TagDescriptions'][0]['Tags']:
156-
if tag['Key'] == 'KubernetesCluster' and tag['Value'] == cluster:
158+
if tag['Key'] == kubeClusterTagKey and tag['Value'] == kubeClusterTagValue:
157159
newTags = prepare_new_tags(tags['TagDescriptions'][0]['Tags'])
158160
if len(newTags) > 0:
159161
LOGGER.info("Adding tags to load balancer %s", elb['LoadBalancerName'])

0 commit comments

Comments
 (0)