From 5a9fa2c808bfd6c905e339f4e7c6b21597b97319 Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Fri, 12 Jul 2024 19:07:10 +0545 Subject: [PATCH] fix: availability zone should be account specific --- fixtures/aws.yaml | 5 ++--- scrapers/aws/aws.go | 16 ++++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/fixtures/aws.yaml b/fixtures/aws.yaml index 3d4355ff..e29a823a 100644 --- a/fixtures/aws.yaml +++ b/fixtures/aws.yaml @@ -39,7 +39,7 @@ spec: # - SecurityGroup transform: relationship: - # EKS Cluster to Kubernetes Cluster & Kubernetes Node + # EKS Cluster to Kubernetes Cluster & Kubernetes Node - filter: config_type == 'AWS::EKS::Cluster' expr: | [ @@ -58,8 +58,7 @@ spec: - filter: config_type == 'AWS::AvailabilityZone' expr: | [ - {"type": "Kubernetes::Node", "tags": {"account": labels['account'], "topology.kubernetes.io/zone": name}}, - {"type": "AWS::AvailabilityZoneID", "name": config["ZoneId"]} + {"type": "Kubernetes::Node", "tags": {"account": labels['account'], "topology.kubernetes.io/zone": name}} ].toJSON() # Region to ZoneID - filter: config_type == 'AWS::Region' diff --git a/scrapers/aws/aws.go b/scrapers/aws/aws.go index 22ee5645..a7896d50 100644 --- a/scrapers/aws/aws.go +++ b/scrapers/aws/aws.go @@ -766,21 +766,21 @@ func (aws Scraper) availabilityZones(ctx *AWSContext, config v1.AWS, results *v1 var uniqueAvailabilityZoneIDs = map[string]struct{}{} for _, az := range azDescribeOutput.AvailabilityZones { - if az.OptInStatus == "opted-in" { - az.OptInStatus = "opt-in-required" - } - *results = append(*results, v1.ScrapeResult{ - ID: lo.FromPtr(az.ZoneName), + ID: fmt.Sprintf("%s-%s", *ctx.Caller.Account, lo.FromPtr(az.ZoneName)), Type: v1.AWSAvailabilityZone, BaseScraper: config.BaseScraper, Config: az, ConfigClass: "AvailabilityZone", Tags: []v1.Tag{{Name: "region", Value: lo.FromPtr(az.RegionName)}}, - Aliases: nil, + Labels: map[string]string{"az-id": lo.FromPtr(az.ZoneId)}, + Aliases: []string{lo.FromPtr(az.ZoneName)}, Name: lo.FromPtr(az.ZoneName), - ScraperLess: true, Parents: []v1.ConfigExternalKey{{Type: v1.AWSRegion, ExternalID: lo.FromPtr(az.RegionName)}}, + RelationshipResults: []v1.RelationshipResult{{ + ConfigExternalID: v1.ExternalID{ExternalID: []string{lo.FromPtr(az.ZoneId)}, ConfigType: v1.AWSAvailabilityZoneID, ScraperID: "all"}, + RelatedExternalID: v1.ExternalID{ExternalID: []string{lo.FromPtr(az.ZoneName)}, ConfigType: v1.AWSAvailabilityZone}, + }}, }) if _, ok := uniqueAvailabilityZoneIDs[lo.FromPtr(az.ZoneId)]; !ok { @@ -1768,7 +1768,7 @@ func (aws Scraper) Scrape(ctx api.ScrapeContext) v1.ScrapeResults { aws.s3Buckets(awsCtx, awsConfig, results) for i, r := range *results { - if lo.Contains([]string{v1.AWSRegion, v1.AWSAvailabilityZone, v1.AWSAvailabilityZoneID}, r.Type) { + if lo.Contains([]string{v1.AWSRegion, v1.AWSAvailabilityZoneID}, r.Type) { // We do not need to add tags to these resources. // They are global resources. continue