Skip to content

Instantly share code, notes, and snippets.

@ciberado
Created November 29, 2022 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ciberado/7966a80fb7e5ad53648a6e03b741581d to your computer and use it in GitHub Desktop.
Save ciberado/7966a80fb7e5ad53648a6e03b741581d to your computer and use it in GitHub Desktop.
#!/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