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

1 change: 1 addition & 0 deletions providers/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func listOfSupportedServices() []providers.FetchDataFunction {
cloudfront.Distributions,
dynamodb.Tables,
ecs.Clusters,
ecs.TaskDefinitions,
ecr.Repositories,
sns.Topics,
ec2.Vpcs,
Expand Down
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
}
29 changes: 29 additions & 0 deletions providers/aws/ecs/taskset.go
ShubhamPalriwala marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ecs

import (
"context"
"fmt"
"time"

log "github.com/sirupsen/logrus"

"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"
. "github.com/tailwarden/komiser/models"
. "github.com/tailwarden/komiser/providers"
)

func TaskSet(ctx context.Context, client ProviderClient) ([]Resource, error) {
resources := make([]Resource, 0)
var config ecs.ListTasksInput
ecsClient := ecs.NewFromConfig(*client.AWSClient)
stsClient := sts.NewFromConfig(*client.AWSClient)
stsOutput, err := ecsClient.ListTaskDefinitions(context.Background(), &config)
if err != nil {
return resources, err
}

accountId := stsOutput

}