-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OCM-12269 | ci: fix with reducing the number of sg in id:73068
- Loading branch information
Showing
3 changed files
with
126 additions
and
2 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,91 @@ | ||
package helper | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/ec2" | ||
. "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/log" | ||
) | ||
|
||
func DescribeInstances(vpcID string, region string) ([]string, error) { | ||
sess := session.Must(session.NewSession(&aws.Config{ | ||
Region: aws.String(region), | ||
})) | ||
ec := ec2.New(sess) | ||
var instanceIDs []string | ||
instances, err := ec.DescribeInstances(&ec2.DescribeInstancesInput{ | ||
Filters: []*ec2.Filter{ | ||
{ | ||
Name: aws.String("vpc-id"), | ||
Values: []*string{aws.String(vpcID)}, | ||
}, | ||
{ | ||
Name: aws.String("instance-state-name"), | ||
Values: []*string{aws.String("pending"), aws.String("running"), aws.String("shutting-down"), aws.String("stopped"), aws.String("stopping")}, | ||
}, | ||
}, | ||
}) | ||
if err != nil { | ||
return instanceIDs, err | ||
} | ||
|
||
for _, reservation := range instances.Reservations { | ||
for _, instance := range reservation.Instances { | ||
instanceIDs = append(instanceIDs, *instance.InstanceId) | ||
Logger.Warnf("Instance ID(Reservation Id %s) %s may leak!", *reservation.ReservationId, *instance.InstanceId) | ||
} | ||
} | ||
return instanceIDs, nil | ||
} | ||
|
||
func DescribeNatGateways(vpcID string, region string) ([]string, error) { | ||
sess := session.Must(session.NewSession(&aws.Config{ | ||
Region: aws.String(region), | ||
})) | ||
ec := ec2.New(sess) | ||
var natGatewayIDs []string | ||
natGateways, err := ec.DescribeNatGateways(&ec2.DescribeNatGatewaysInput{ | ||
Filter: []*ec2.Filter{ | ||
{ | ||
Name: aws.String("vpc-id"), | ||
Values: []*string{aws.String(vpcID)}, | ||
}, | ||
{ | ||
Name: aws.String("state"), | ||
Values: []*string{aws.String("available"), aws.String("deleting"), aws.String("pending")}, | ||
}, | ||
}, | ||
}) | ||
if err != nil { | ||
return natGatewayIDs, err | ||
} | ||
for _, ngw := range natGateways.NatGateways { | ||
natGatewayIDs = append(natGatewayIDs, *ngw.NatGatewayId) | ||
Logger.Warnf("NatGateway Id %s may leak!", *ngw.NatGatewayId) | ||
} | ||
return natGatewayIDs, nil | ||
} | ||
|
||
func DescribeNetworkInterfaces(vpcID string, region string) ([]string, error) { | ||
sess := session.Must(session.NewSession(&aws.Config{ | ||
Region: aws.String(region), | ||
})) | ||
ec := ec2.New(sess) | ||
var networkInterfaceIDs []string | ||
networkInterfaces, err := ec.DescribeNetworkInterfaces(&ec2.DescribeNetworkInterfacesInput{ | ||
Filters: []*ec2.Filter{ | ||
{ | ||
Name: aws.String("vpc-id"), | ||
Values: []*string{aws.String(vpcID)}, | ||
}, | ||
}, | ||
}) | ||
if err != nil { | ||
return networkInterfaceIDs, err | ||
} | ||
for _, ni := range networkInterfaces.NetworkInterfaces { | ||
networkInterfaceIDs = append(networkInterfaceIDs, *ni.NetworkInterfaceId) | ||
Logger.Warnf("NetworkInterface Id %s may leak!", *ni.NetworkInterfaceId) | ||
} | ||
return networkInterfaceIDs, nil | ||
} |
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