Skip to content

Commit

Permalink
feat: Add checkKeyName function to prevent the script from asking to …
Browse files Browse the repository at this point in the history
…duplicate key pairs to the AWS
  • Loading branch information
hiroTochigi committed Jul 25, 2024
1 parent 386b1e3 commit 8f14681
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/aws/up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@ groupName=luftballons-sg
instanceName=luftballon
checkSSH=~/.ssh/$publickey


checkKeyName() {
key_pairs=($(aws ec2 describe-key-pairs --query "KeyPairs[*].KeyName" --output text))

for key in "${key_pairs[@]}"
do
if [ "$key" == "$keyName" ]; then
echo "Error: Key Pair '$key' matches the specified keyName '$keyName'. Exiting..."
exit 1
fi
done
}

function importSshKey()
{
Expand Down Expand Up @@ -149,6 +159,7 @@ function up {
keyname=luftballon
fi

checkKeyName

keyName=$(importSshKey | getValueByKeyword KeyName )

Expand Down

0 comments on commit 8f14681

Please sign in to comment.