Skip to content

Commit ea47854

Browse files
committed
feat(account): support guardduty regional delegated administration
1 parent b8b0873 commit ea47854

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

modules/account/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ This module creates following resources.
88
- `aws_cloudtrail_organization_delegated_admin_account` (optional)
99
- `aws_fms_admin_account` (optional)
1010
- `aws_guardduty_organization_admin_account` (optional)
11+
- `aws_inspector2_delegated_admin_account` (optional)
12+
- `aws_macie2_organization_admin_account` (optional)
1113
- `aws_securityhub_organization_admin_account` (optional)
1214
- `aws_vpc_ipam_organization_admin_account` (optional)
13-
- `aws_macie2_organization_admin_account` (optional)
14-
- `aws_inspector2_delegated_admin_account` (optional)
1515
- `aws_account_primary_contact` (optional)
1616
- `aws_account_alternate_contact` (optional)
1717
- `aws_account_region` (optional)

modules/account/delegated-administrators.tf

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ locals {
1111
"securityhub.amazonaws.com",
1212
]
1313
regional_services = [
14+
"guardduty.amazonaws.com",
1415
"inspector2.amazonaws.com",
1516
"macie.amazonaws.com",
1617
]
@@ -75,12 +76,6 @@ resource "aws_fms_admin_account" "this" {
7576
account_id = aws_organizations_account.this.id
7677
}
7778

78-
resource "aws_guardduty_organization_admin_account" "this" {
79-
count = contains(local.delegated_service_names, "guardduty.amazonaws.com") ? 1 : 0
80-
81-
admin_account_id = aws_organizations_account.this.id
82-
}
83-
8479
resource "aws_securityhub_organization_admin_account" "this" {
8580
count = contains(local.delegated_service_names, "securityhub.amazonaws.com") ? 1 : 0
8681

@@ -93,6 +88,20 @@ resource "aws_vpc_ipam_organization_admin_account" "this" {
9388
delegated_admin_account_id = aws_organizations_account.this.id
9489
}
9590

91+
resource "aws_guardduty_organization_admin_account" "this" {
92+
for_each = toset(contains(local.delegated_service_names, "guardduty.amazonaws.com")
93+
? (length(local.delegated_services_map["guardduty.amazonaws.com"].regions) > 0
94+
? local.delegated_services_map["guardduty.amazonaws.com"].regions
95+
: local.all_available_regions
96+
)
97+
: []
98+
)
99+
100+
region = each.key
101+
102+
admin_account_id = aws_organizations_account.this.id
103+
}
104+
96105
resource "aws_macie2_organization_admin_account" "this" {
97106
for_each = toset(contains(local.delegated_service_names, "macie.amazonaws.com")
98107
? (length(local.delegated_services_map["macie.amazonaws.com"].regions) > 0

0 commit comments

Comments
 (0)