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

Conversation

aimanafzal
Copy link
Contributor

@ChristianWitts
Please review the PR

Thanks!

Copy link
Collaborator

@mlabouardy mlabouardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @aimanafzal for the PR
You need to invoke the function [here] :)(https://github.com/tailwarden/komiser/blob/develop/providers/aws/aws.go#L38)

@mlabouardy mlabouardy added the aws label Jun 28, 2023
@mlabouardy mlabouardy added this to the v3.0.20 milestone Jun 28, 2023
@aimanafzal
Copy link
Contributor Author

Thanks @aimanafzal for the PR
You need to invoke the function [here] :)(https://github.com/tailwarden/komiser/blob/develop/providers/aws/aws.go#L38)

My bad.
Sorry..
Done!

@mlabouardy
Copy link
Collaborator

Thanks @aimanafzal for the PR
You need to invoke the function [here] :)(https://github.com/tailwarden/komiser/blob/develop/providers/aws/aws.go#L38)

My bad. Sorry.. Done!

Thanks, can you fix the conflicts as well? :)

@aimanafzal
Copy link
Contributor Author

Please take a look at it.

Copy link
Collaborator

@ShubhamPalriwala ShubhamPalriwala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @aimanafzal, thanks a lot for this PR! I just tested it locally and I can see the resource 🚀 :
Screenshot_2023-06-30-17-03-04_4920x1920

However, I would be really glad if you could possibly make the following fixes as well and then we should be gtg:

@aimanafzal
Copy link
Contributor Author

Cool.
Let me look at it sometime in the day.

@ShubhamPalriwala
Copy link
Collaborator

Hey @aimanafzal let me know if you are stuck somewhere or need any help here 🙏🏼

@aimanafzal
Copy link
Contributor Author

aimanafzal commented Jul 5, 2023 via email

@ShubhamPalriwala
Copy link
Collaborator

Hey @aimanafzal, you can parse the ECS Task def name and the revision w the below function:

func extractNameAndRevisionFromArn(input string) []string {
	var nameAndRevision [2]string
	parts := strings.Split(input, ":")
	if len(parts) >= 6 {
		nameAndRevision[0] = strings.Split(parts[5], "/")[1]
		nameAndRevision[1] = parts[6]
	}
	return nameAndRevision[:]
}

And call it like this:

ecsNameAndRevision := extractNameAndRevisionFromArn(taskdefinition)

Now you can append the resource as:

			resources = append(resources, Resource{
				Provider:   "AWS",
				Account:    client.Name,
				Service:    "ECS Task Definition",
				ResourceId: taskdefinition,
				Region:     client.AWSClient.Region,
				Name:       ecsNameAndRevision[0],
				Cost:       0,
				FetchedAt:  time.Now(),
				Link:       fmt.Sprintf("https://%s.console.aws.amazon.com/ecs/v2/task-definitions/%s/%s/containers?region=%s", client.AWSClient.Region, ecsNameAndRevision[0], ecsNameAndRevision[1], client.AWSClient.Region),
			})

Another small overhead I found is the calculation of the resource Arn which we do not need hence you can remove the below code from your file:

	stsClient := sts.NewFromConfig(*client.AWSClient)
	stsoutput, err := stsClient.GetCallerIdentity(ctx, &sts.GetCallerIdentityInput{})
	if err != nil {
		return resources, err
	}
	accountId := stsoutput.Account

and the ResourceId can directly become the taskdefinition!

This should solve and get the PR merged, as I have tested it locally as well. Let me know what you think 💯

@aimanafzal
Copy link
Contributor Author

aimanafzal commented Jul 6, 2023 via email

@mlabouardy mlabouardy modified the milestones: v3.0.20, v3.1.0 Jul 6, 2023
@ShubhamPalriwala
Copy link
Collaborator

Hey @aimanafzal, I made a small correction in the URL for the resource and the PR is good to be merged now! thanks a lot for building this feature 💯

@mlabouardy please take a look at the changes once and then i'll proceed!

@aimanafzal
Copy link
Contributor Author

aimanafzal commented Jul 10, 2023 via email

@mlabouardy mlabouardy self-requested a review July 10, 2023 16:44
Copy link
Collaborator

@mlabouardy mlabouardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ShubhamPalriwala ShubhamPalriwala merged commit e7083d3 into tailwarden:develop Jul 10, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants