Skip to content

Commit

Permalink
fix: availability zone should be account specific
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe authored and moshloop committed Jul 14, 2024
1 parent 9a98818 commit 42a47d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
5 changes: 2 additions & 3 deletions fixtures/aws.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
[
Expand All @@ -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'
Expand Down
16 changes: 8 additions & 8 deletions scrapers/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -1769,7 +1769,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
Expand Down

0 comments on commit 42a47d0

Please sign in to comment.