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

[New Resource]: Delegated Administrator for CloudTrail #29179

Closed
posquit0 opened this issue Jan 31, 2023 · 9 comments · Fixed by #38817
Closed

[New Resource]: Delegated Administrator for CloudTrail #29179

posquit0 opened this issue Jan 31, 2023 · 9 comments · Fixed by #38817
Labels
new-resource Introduces a new resource. service/cloudtrail Issues and PRs that pertain to the cloudtrail service. service/organizations Issues and PRs that pertain to the organizations service.
Milestone

Comments

@posquit0
Copy link
Contributor

Description

Requested Resource(s) and/or Data Source(s)

  • aws_cloudtrail_organization_admin_account

Potential Terraform Configuration

resource "aws_cloudtrail_organization_admin_account" "example" {
  delegated_admin_account_id = data.aws_caller_identity.delegated.account_id
}

data "aws_caller_identity" "delegated" {
  provider = aws.ipam_delegate_account
}

References

Would you like to implement a fix?

None

@posquit0 posquit0 added the needs-triage Waiting for first response or review from a maintainer. label Jan 31, 2023
@github-actions
Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@github-actions github-actions bot added service/cloudtrail Issues and PRs that pertain to the cloudtrail service. service/sts Issues and PRs that pertain to the sts service. labels Jan 31, 2023
@justinretzolk justinretzolk added new-resource Introduces a new resource. and removed needs-triage Waiting for first response or review from a maintainer. labels Jan 31, 2023
@gdavison gdavison added service/organizations Issues and PRs that pertain to the organizations service. and removed service/sts Issues and PRs that pertain to the sts service. labels Feb 1, 2023
@rojones94
Copy link

rojones94 commented Jun 1, 2023

You can delegate admin control in the following way.

resource "aws_organizations_delegated_administrator" "this" {
  account_id        = "your-account-id"
  service_principal = "cloudtrail.amazonaws.com"
}

@posquit0
Copy link
Contributor Author

posquit0 commented Jun 9, 2023

@rojones94 No, there is a dedicated API for registering cloudtrail delegated administrator.
Your suggested AWS Organization API is not working for many AWS services.

https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-delegated-administrator.html

@jorhett
Copy link

jorhett commented Dec 2, 2023

You can delegate admin control in the following way.

resource "aws_organizations_delegated_administrator" "this" {
  account_id        = "your-account-id"
  service_principal = "cloudtrail.amazonaws.com"
}

Actually, this will not work and will prevent delegation from working. Just to explain how bad this is, if you do the delegation this way it appears to work, but you can't do anything.

If you try to run this command after applying the resource quoted above you'll see this:

$ aws cloudtrail register-organization-delegated-admin --member-account-id="123456789012"
An error occurred (AccountRegisteredException) when calling the RegisterOrganizationDelegatedAdmin operation: The specified AWS account 370208956287 is already registered as the CloudTrail delegated administrator.

You must delete the aws_organizations_delegated_administrator resource, apply the change, then run this CLI command to achieve the working solution:

$ aws cloudtrail register-organization-delegated-admin --member-account-id="123456789012"

This is why a new resource utilizing the Cloudtrail APIs is required.

@AugustoEMoreira
Copy link

You can delegate admin control in the following way.

resource "aws_organizations_delegated_administrator" "this" {
  account_id        = "your-account-id"
  service_principal = "cloudtrail.amazonaws.com"
}

I'm curious did you have already implemented delegated admin for cloudtrail using this? If so, could you explain? Because AWS has absolutely no documentation on how to do it using the organization's APIs instead of Cloudtrail's

@AugustoEMoreira
Copy link

AugustoEMoreira commented Apr 27, 2024

@posquit0 After some research, I found the solution.
When enabling delegated administrator access using Organizations API, AWS doesn't create a service-linked role to cloudtrail.
To make this work, you will need to create a new resource like this:

resource "aws_iam_service_linked_role" "cloudtrail_service_role" {
    aws_service_name = "cloudtrail.amazonaws.com"
}

This resource should be in your root account. Also, you are going to need to set up s3's policy manually; I will assume you know how to do it, but let me know if you need further help.

Copy link

Warning

This issue has been closed, meaning that any additional comments are hard for our team to see. Please assume that the maintainers will not see them.

Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed.

@github-actions github-actions bot added this to the v5.63.0 milestone Aug 13, 2024
Copy link

This functionality has been released in v5.63.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
new-resource Introduces a new resource. service/cloudtrail Issues and PRs that pertain to the cloudtrail service. service/organizations Issues and PRs that pertain to the organizations service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants