Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ECS Task Definition #868

59 changes: 59 additions & 0 deletions providers/aws/ecs/taskDefinitions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package ecs

import (
"context"
"fmt"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/ecs"
"github.com/aws/aws-sdk-go-v2/service/sts"
log "github.com/sirupsen/logrus"
. "github.com/tailwarden/komiser/models"
. "github.com/tailwarden/komiser/providers"
)

func TaskDefinitions(ctx context.Context, client ProviderClient) ([]Resource, error) {
resources := make([]Resource, 0)
var config ecs.ListTaskDefinitionsInput
ecsClient := ecs.NewFromConfig(*client.AWSClient)
stsClient := sts.NewFromConfig(*client.AWSClient)
stsoutput, err := stsClient.GetCallerIdentity(ctx, &sts.GetCallerIdentityInput{})
if err != nil {
return resources, err
}
accountId := stsoutput.Account

for {
output, err := ecsClient.ListTaskDefinitions(context.Background(), &config)
if err != nil {
return resources, err
}
for _, taskdefinition := range output.TaskDefinitionArns {
resourceArn := fmt.Sprintf("arn:aws:ecs:%s:%s:taskdefinition/%s", client.AWSClient.Region, *accountId, taskdefinition)
resources = append(resources, Resource{
Provider: "AWS",
Account: client.Name,
Service: "ECS Task Definition",
ResourceId: resourceArn,
Region: client.AWSClient.Region,
Name: taskdefinition,
Cost: 0,
FetchedAt: time.Now(),
Link: fmt.Sprintf("https://%s.console.aws.amazon.com/ecs/home?#/taskdefinition/%s", client.AWSClient.Region, taskdefinition),
})
}
if aws.ToString(output.NextToken) == "" {
break
}
config.NextToken = output.NextToken
}
log.WithFields(log.Fields{
"provider": "AWS",
"account": client.Name,
"region": client.AWSClient.Region,
"service": "ECS Task Definition",
"resources": len(resources),
}).Info("Fetched resources")
return resources, nil
}