Skip to content

Commit

Permalink
feat: setup hard relationship to cloudfo stack
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Jul 4, 2024
1 parent 3a4cd81 commit bf26933
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion scrapers/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ func (aws Scraper) cloudformationStacks(ctx *AWSContext, config v1.AWS, results
ConfigClass: "Stack",
Name: stackName,
ID: stackName,
Aliases: []string{lo.FromPtr(stack.StackId)},
Parents: []v1.ConfigExternalKey{{Type: v1.AWSAccount, ExternalID: lo.FromPtr(ctx.Caller.Account)}},
}.WithHealthStatus(resourceHealth))
}
Expand Down Expand Up @@ -1608,7 +1609,23 @@ func (aws Scraper) Scrape(ctx api.ScrapeContext) v1.ScrapeResults {
aws.trustedAdvisor(awsCtx, awsConfig, results)
aws.s3Buckets(awsCtx, awsConfig, results)

for i := range *results {
for i, r := range *results {
if stack, ok := r.Labels["aws:cloudformation:stack-id"]; ok {
if len(r.Parents) != 0 {
// the default parent should be moved to soft relationship
defaultParent := r.Parents[0]
(*results)[i].RelationshipResults = append((*results)[i].RelationshipResults, v1.RelationshipResult{
ConfigExternalID: v1.ExternalID{ConfigType: defaultParent.Type, ExternalID: []string{defaultParent.ExternalID}},
RelatedExternalID: v1.ExternalID{ConfigType: r.Type, ExternalID: []string{r.ID}},
})
}

(*results)[i].Parents = append([]v1.ConfigExternalKey{{
Type: v1.AWSCloudFormationStack,
ExternalID: stack,
}}, (*results)[i].Parents...)
}

(*results)[i].Tags = append((*results)[i].Tags, v1.Tag{
Name: "account",
Value: lo.FromPtr(awsCtx.Caller.Account),
Expand Down

0 comments on commit bf26933

Please sign in to comment.