-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdescribe_subnets.sh
executable file
·55 lines (55 loc) · 1.26 KB
/
describe_subnets.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
#
# AWS - Describe subnets
#
export AWS_DEFAULT_REGION=us-east-1
echo "AWS_DEFAULT_REGION= " $AWS_DEFAULT_REGION
#
# Is there a VPC with CIDR 172.16.0.0/16?
default_cidr="172.16.0.0/16"
read -p "CIDR? (default: $default_cidr) " cidr
#
# if $cidr value that's input has regex pattern ^$, it's empty, so use default
if [[ "$cidr" =~ ^$ ]]; then
cidr=$default_cidr
echo "using default CIDR $default_cidr";
fi
# Describe VPCs
# Describe VPC results fields
# 1- "VPCS"
# 2- CidrBlock
# 3- DhcpOptionsId
# 4- InstanceTenancy
# 5- IsDefault
# 6- State
# 7- VpcId
#
# get VpcId from field 7
vpc=$(aws ec2 describe-vpcs --output text --filters Name=cidr,Values=$cidr | cut -f 7)
# if $vpc = regex ^$, then no VPC with specified CIDR
if [[ "$vpc" =~ ^$ ]]; then
echo "No VPC with CIDR $cidr"
exit
#lse
# aws ec2 describe-vpcs --output table --filters Name=cidr,Values=$cidr
fi
#
# Describe subnets
# Describe subnet fields
# 1- "SUBNETS"
# 2- AvailabilityZone
# 3- AvailableIpAddressCount
# 4- CidrBlock
# 5- DefaultForAz
# 6- MapPublicIpOnLaunch
# 7- State
# 8- SubnetId
# 9- VpcId
echo "VPC " $vpc
if [ "$vpc" ]; then
echo ""
aws ec2 describe-subnets --output text --filters Name=vpc-id,Values=$vpc
else
echo ""
echo "No VPC subnets for CIDR $cidr"
fi