Skip to content

Allow colons in tag names #1753

@nitrocode

Description

@nitrocode

I work with a client that uses colons in tag names as part of aws best tagging practices.

I tried to do this and I could not get it to work with tag corp:env and value prod

aws-gate session corp:env:prod
aws-gate session corp\:env:prod
aws-gate session "corp:env":prod
aws-gate session "corp\:env":prod

Seems like colons in tag names aren't supported by aws-gate yet. However, they are supported by aws.

Thank you for considering this

def getinstanceidbytag(name, ec2=None):
# One of the allowed characters in tags is ":", which might break tag
# parsing. For this reason,we have to differentiate 2 cases for
# provided name:
# - aws: special prefixed tags in the form of aws:<service>:<tag_name>:<tag_value>
# - regular cases in the form <tag_name>:<tag_value>
if name.startswith("aws:"):
key, value = ":".join(name.split(":", 3)[:3]), name.split(":", 3)[-1]
else:
key, value = name.split(":", 1)
filters = [{"Name": f"tag:{key}", "Values": [value]}]
return _query_aws_api(filters=filters, ec2=ec2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions