-
Notifications
You must be signed in to change notification settings - Fork 83
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
get-vpc-id-by-name #15
base: master
Are you sure you want to change the base?
Conversation
How about adding a get-vpc-name-by-id like this? aws ec2 describe-vpcs --filter "Name=vpc-id,Values=${1}" --query 'Vpcs[*].Tags[].Value' --output text |
Added, I like that it matches a partial vpc-id as well |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I like both aliases. I just had a feedback comment for both of the aliases.
|
||
get-vpc-id-by-name = | ||
!f() { | ||
aws ec2 describe-vpcs --filter "Name=tag:Name,Values=${1}" --query 'Vpcs[*].{id:VpcId}' --output text |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should be able to simplify your --query
by just making it: --query 'Vpcs[].[VpcId]
and should be the same result
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kyleknap the alias as submitted with curly braces, seems correct.
$ aws ec2 describe-vpcs --filter "Name=tag:Name,Values=vpc_name" --query 'Vpcs[].[id:VpcId]' --output text
Bad value for --query Vpcs[].[id:VpcId]: Expecting: comma, got: colon: Parse error at column 10, token ":" (COLON), for expression:
"Vpcs[].[id:VpcId]"
^
$ aws ec2 describe-vpcs --filter "Name=tag:Name,Values=vpc_name" --query 'Vpcs[].{id:VpcId}' --output text
vpc-01234567890123456
However, @fdavis you can also do this:
aws ec2 describe-vpcs --filter "Name=tag:Name,Values=${1}" --query 'Vpcs[*].{id:VpcId}' --output text | |
aws ec2 describe-vpcs --query "Vpcs[?Tags[?Key==\`Name\`]|[?Value==\`${1:?Need a VPC Name}\`]].VpcId" --output text |
|
||
get-vpc-name-by-id = | ||
!f() { | ||
aws ec2 describe-vpcs --filter "Name=vpc-id,Values=${1}" --query 'Vpcs[*].Tags[].Value' --output text |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like we are including values of all tags. I think we should only be including the Name
tag in what is returned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also recommend to include only the tag Name
. +1 to include these 2 in the aliases.
|
||
get-vpc-name-by-id = | ||
!f() { | ||
aws ec2 describe-vpcs --filter "Name=vpc-id,Values=${1}" --query 'Vpcs[*].Tags[].Value' --output text |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aws ec2 describe-vpcs --filter "Name=vpc-id,Values=${1}" --query 'Vpcs[*].Tags[].Value' --output text | |
aws ec2 describe-vpcs --vpc-ids "${1:?Need a VPCId}" --query 'Vpcs[].Tags[?Key==`Name`].Value' --output text |
we have a lot of accounts and vpcs so its helpful to be able to grab a vpc-id for other configs/placement