Skip to content

Commit

Permalink
Enhance up function to handle terminated EC2 instances
Browse files Browse the repository at this point in the history
- Added check for terminated EC2 instance state
- Execute instance creation steps when instance state is terminated
- Ensure consistent behavior for creating and running EC2 instances when necessary
  • Loading branch information
hiroTochigi committed Aug 1, 2024
1 parent 4fc81d6 commit 8ca0b8a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/aws/up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,13 @@ function up {

instanceId=$(checkInstance)
if [ -z "$instanceId" ]; then
instanceId=$(createEc2 | getValueByKeyword InstanceId )
instanceState=""
else
instanceState=$(checkInstanceState $instanceId)
fi

if [ -z "$instanceId" ] || [ "$instanceState" = "terminated" ]; then
instanceId=$(createEc2 | getValueByKeyword InstanceId)
echo "Creating and running EC2 instance..."

echo "Instance id is $instanceId"
Expand All @@ -206,7 +212,6 @@ function up {

storeConfigIntoTreehousesConfigAsStringfiedJson $instanceName $importedKeyName $instanceId $publicIp $groupNameaws ec2 create-tags --resources $instanceId --tags Key=Class,Value=treehouses
else
instanceState=$(checkInstanceState $instanceId)
if [ "$instanceState" = "running" ]; then
echo "EC2 instance is already running."
elif [ "$instanceState" = "stopped" ]; then
Expand Down

0 comments on commit 8ca0b8a

Please sign in to comment.