Created
November 29, 2022 16:22
-
-
Save ciberado/7966a80fb7e5ad53648a6e03b741581d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ $# -eq 0 ]] ; then | |
echo 'Provide the name of the owner, please.' | |
exit 0 | |
fi | |
OWNER=$1 | |
VPC_ID=$(aws ec2 create-vpc \ | |
--cidr-block 10.0.0.0/16 \ | |
--tag-specification \ | |
"ResourceType=vpc,Tags=[{Key=Name,Value=pokemon-$OWNER},{Key=Owner,Value=$OWNER}]" \ | |
--query Vpc.VpcId \ | |
--output text) | |
echo The VPC ID is $VPC_ID. | |
SG_ID=$(aws ec2 create-security-group \ | |
--group-name web \ | |
--description "Web security group ($OWNER)" \ | |
--vpc-id $VPC_ID \ | |
--query GroupId \ | |
--output text) | |
echo The SG ID is $SG_ID. | |
aws ec2 authorize-security-group-ingress \ | |
--group-id $SG_ID \ | |
--protocol tcp \ | |
--port 80 \ | |
--cidr 0.0.0.0/0 > /dev/null | |
echo Inbound rule created. | |
SUBNET_ID=$(aws ec2 create-subnet \ | |
--vpc-id $VPC_ID \ | |
--cidr-block 10.0.0.0/24 \ | |
--tag-specification \ | |
"ResourceType=subnet,Tags=[{Key=Name,Value=pokemon-$OWNER},{Key=Owner,Value=$OWNER}]" \ | |
--query Subnet.SubnetId \ | |
--output text) | |
echo The subnet ID is $SUBNET_ID. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment