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

Allow users to opt-out of changing instance name tags #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lizard-boy
Copy link

I was very surprised when my instance names changed after adding this. I much prefer their original names, so I added a way to opt-out of of them being change. 😄

@lizard-boy
Copy link
Author

@greptileai

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This pull request introduces a new feature allowing users to opt-out of changing instance name tags in Auto Scaling Groups (ASGs). The changes primarily affect the README.md and lambda/autoscale/autoscale.py files.

  • Added new asg:update_instance_name tag in lambda/autoscale/autoscale.py to control instance name tag updates
  • Updated README.md with documentation on how to use the new opt-out feature
  • Modified fetch_tag_metadata and process_message functions in lambda/autoscale/autoscale.py to implement the opt-out logic
  • CHANGELOG.md should be updated to reflect this new feature
  • Consider adding tests for the new opt-out functionality

2 file(s) reviewed, 4 comment(s)
Edit PR Review Bot Settings

Comment on lines +53 to 59
tags = autoscaling.describe_tags(
Filters=[
{'Name': 'auto-scaling-group','Values': [asg_name]},
{'Name': 'key','Values': [HOSTNAME_TAG_NAME]}
{'Name': 'key','Values': [HOSTNAME_TAG_NAME, UPDATE_INSTANCE_TAG_NAME]}
],
MaxRecords=1
)['Tags'][0]['Value']
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: The 'Tags' key is accessed without checking if it exists or if it's empty. This could lead to an IndexError if no tags are found.

Comment on lines +61 to +63
tag_values = {
tag['Key']: tag['Value'] for tag in tags
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: This dictionary comprehension assumes that 'tags' is a list of dictionaries with 'Key' and 'Value' keys. However, 'tags' is actually the value of the first tag found. This will likely cause a runtime error.

Comment on lines +135 to +136
if asg_tag_metadata.get(UPDATE_INSTANCE_TAG_NAME, "true") == "true":
update_name_tag(instance_id, hostname)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: The default value 'true' is a string, not a boolean. Consider using a boolean default value instead.

@@ -12,6 +12,7 @@
route53 = boto3.client('route53')

HOSTNAME_TAG_NAME = "asg:hostname_pattern"
UPDATE_INSTANCE_TAG_NAME = "asg:update_instance_name"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider adding a comment explaining the purpose and expected values of UPDATE_INSTANCE_TAG_NAME for better code documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants