-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🧹 aws fixes; make aws ec2 instance-connect and aws ec2 ssm work (#1707)
- Loading branch information
Showing
14 changed files
with
1,150 additions
and
18 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) Mondoo, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package awsec2ebsconn | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go-v2/service/ec2" | ||
"github.com/aws/aws-sdk-go-v2/service/ec2/types" | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/rs/zerolog/log" | ||
awsec2ebstypes "go.mondoo.com/cnquery/providers/aws/connection/awsec2ebsconn/types" | ||
) | ||
|
||
func (c *AwsEbsConnection) DetachVolumeFromInstance(ctx context.Context, volume *awsec2ebstypes.VolumeInfo) error { | ||
log.Info().Msg("detach volume") | ||
res, err := c.scannerRegionEc2svc.DetachVolume(ctx, &ec2.DetachVolumeInput{ | ||
Device: aws.String(c.volumeMounter.VolumeAttachmentLoc), VolumeId: &volume.Id, | ||
InstanceId: &c.scannerInstance.Id, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
if res.State != types.VolumeAttachmentStateDetached { // check if it's detached already | ||
var volState types.VolumeState | ||
for volState != types.VolumeStateAvailable { | ||
time.Sleep(10 * time.Second) | ||
resp, err := c.scannerRegionEc2svc.DescribeVolumes(ctx, &ec2.DescribeVolumesInput{VolumeIds: []string{volume.Id}}) | ||
if err != nil { | ||
return err | ||
} | ||
if len(resp.Volumes) == 1 { | ||
volState = resp.Volumes[0].State | ||
|
||
log.Info().Interface("state", volState).Msg("waiting for volume detachment completion") | ||
} | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (c *AwsEbsConnection) DeleteCreatedVolume(ctx context.Context, volume *awsec2ebstypes.VolumeInfo) error { | ||
log.Info().Msg("delete created volume") | ||
_, err := c.scannerRegionEc2svc.DeleteVolume(ctx, &ec2.DeleteVolumeInput{VolumeId: &volume.Id}) | ||
return err | ||
} |
Oops, something went wrong.