Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

Commit

Permalink
waiting instance status check till ok then ssh
Browse files Browse the repository at this point in the history
  • Loading branch information
tedteng committed Apr 29, 2020
2 parents 80a0c7c + 5d340b8 commit 64c5fbc
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions pkg/cmd/ssh_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ func sshToAWSNode(nodeName, path, user, pathSSKeypair string, sshPublicKey []byt
if cachevar {
fmt.Println("(3/4) Creating bastion host - skipping")
a.getBastionHostInstance()
if a.BastionInstanceID != "" {
a.cleanupAwsBastionHost()
os.Exit(0)
}
a.cleanupAwsBastionHost()
os.Exit(0)
}

defer a.cleanupAwsBastionHost()
Expand Down Expand Up @@ -334,13 +332,20 @@ func (a *AwsInstanceAttribute) cleanupAwsBastionHost() {
fmt.Println("")

// clean up bastion host instance
fmt.Println(" (1/3) Cleaning up bastion host instance")
arguments := fmt.Sprintf("aws ec2 terminate-instances --instance-ids %s", a.BastionInstanceID)
arguments := "aws ec2 describe-instances --instance-ids " + a.BastionInstanceID + " --output text"
captured := capture()
operate("aws", arguments)
capturedOutput, err := captured()
checkError(err)
fmt.Println(capturedOutput)
if len(capturedOutput) > 0 {
fmt.Println(" (1/3) Cleaning up bastion host instance")
arguments := fmt.Sprintf("aws ec2 terminate-instances --instance-ids %s", a.BastionInstanceID)
captured := capture()
operate("aws", arguments)
capturedOutput, err := captured()
checkError(err)
fmt.Println(capturedOutput)
}

// remove ssh rule from ec2 instance
fmt.Println(" (2/3) Close SSH Port on Node.")
Expand All @@ -350,7 +355,6 @@ func (a *AwsInstanceAttribute) cleanupAwsBastionHost() {
operate("aws", arguments)
capturedOutput, err = captured()
checkError(err)

if len(capturedOutput) > 0 {
arguments = fmt.Sprintf("aws ec2 revoke-security-group-ingress --group-id %s --protocol tcp --port 22 --cidr 0.0.0.0/0", a.SecurityGroupID)
captured = capture()
Expand Down

0 comments on commit 64c5fbc

Please sign in to comment.