From bdd44d798ce96dd2f344347f33cf9f08b86b9984 Mon Sep 17 00:00:00 2001 From: Tiago Silva Date: Thu, 25 Jul 2024 14:30:14 +0100 Subject: [PATCH] correctly propagate ec2 instance region (#44622) this PR correctly propagates the region of a certain EC2 instance instead of relying on availability zone. Signed-off-by: Tiago Silva --- lib/srv/discovery/fetchers/aws-sync/ec2.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/srv/discovery/fetchers/aws-sync/ec2.go b/lib/srv/discovery/fetchers/aws-sync/ec2.go index e2962cfc346b7..b6a7be2ecb424 100644 --- a/lib/srv/discovery/fetchers/aws-sync/ec2.go +++ b/lib/srv/discovery/fetchers/aws-sync/ec2.go @@ -90,7 +90,7 @@ func (a *awsFetcher) fetchAWSEC2Instances(ctx context.Context) ([]*accessgraphv1 lHosts := make([]*accessgraphv1alpha.AWSInstanceV1, 0, len(page.Reservations)) for _, reservation := range page.Reservations { for _, instance := range reservation.Instances { - hosts = append(hosts, awsInstanceToProtoInstance(instance, a.AccountID)) + hosts = append(hosts, awsInstanceToProtoInstance(instance, region, a.AccountID)) } } collectHosts(lHosts, nil) @@ -110,7 +110,7 @@ func (a *awsFetcher) fetchAWSEC2Instances(ctx context.Context) ([]*accessgraphv1 // awsInstanceToProtoInstance converts an ec2.Instance to accessgraphv1alpha.AWSInstanceV1 // representation. -func awsInstanceToProtoInstance(instance *ec2.Instance, accountID string) *accessgraphv1alpha.AWSInstanceV1 { +func awsInstanceToProtoInstance(instance *ec2.Instance, region string, accountID string) *accessgraphv1alpha.AWSInstanceV1 { var tags []*accessgraphv1alpha.AWSTag for _, tag := range instance.Tags { tags = append(tags, &accessgraphv1alpha.AWSTag{ @@ -125,7 +125,7 @@ func awsInstanceToProtoInstance(instance *ec2.Instance, accountID string) *acces } return &accessgraphv1alpha.AWSInstanceV1{ InstanceId: aws.ToString(instance.InstanceId), - Region: aws.ToString(instance.Placement.AvailabilityZone), + Region: region, PublicDnsName: aws.ToString(instance.PublicDnsName), LaunchKeyName: strPtrToWrapper(instance.KeyName), IamInstanceProfileArn: instanceProfileMetadata,