Skip to content

Commit f6acef6

Browse files
committed
add support to override accounts to exclude when auto enrolling
1 parent ce5ac79 commit f6acef6

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ For deployment in a delegated administrator account:
5252

5353
```hcl
5454
module "inspector" {
55-
source = "rhythmictech/inspector/aws"
56-
is_delegated_admin = true
57-
auto_enable_ec2 = true
58-
auto_enable_ecr = true
59-
auto_enable_lambda = true
60-
auto_associate_org_members = true
61-
create_notification_topic = true
55+
source = "rhythmictech/inspector/aws"
56+
is_delegated_admin = true
57+
auto_enable_ec2 = true
58+
auto_enable_ecr = true
59+
auto_enable_lambda = true
60+
enable_inspector_for_all_accounts = true
61+
create_notification_topic = true
6262
}
6363
```
6464

@@ -90,15 +90,14 @@ This minimal setup enables Inspector for the member account and creates a local
9090

9191
```hcl
9292
module "inspector" {
93-
source = "rhythmictech/inspector/aws"
94-
account_ids = ["123456789012", "210987654321"]
95-
delegated_admin_account_id = "123456789012"
96-
auto_associate_org_members = true
97-
is_delegated_admin = true
98-
auto_enable_ec2 = true
99-
auto_enable_ecr = true
100-
auto_enable_lambda = true
101-
create_notification_topic = true
93+
source = "rhythmictech/inspector/aws"
94+
is_delegated_admin = true
95+
auto_enable_ec2 = true
96+
auto_enable_ecr = true
97+
auto_enable_lambda = true
98+
create_notification_topic = true
99+
enable_inspector_for_all_accounts = true
100+
exclude_account_ids = ["123456789012", "210987654321"]
102101
}
103102
```
104103

@@ -151,6 +150,7 @@ No modules.
151150
| <a name="input_delegated_admin_account_id"></a> [delegated\_admin\_account\_id](#input\_delegated\_admin\_account\_id) | The AWS account ID to be set as a delegated administrator for Inspector | `string` | `null` | no |
152151
| <a name="input_enable_inspector"></a> [enable\_inspector](#input\_enable\_inspector) | Whether to enable Inspector for the current account | `bool` | `true` | no |
153152
| <a name="input_enable_inspector_for_all_accounts"></a> [enable\_inspector\_for\_all\_accounts](#input\_enable\_inspector\_for\_all\_accounts) | Whether to enable Inspector for all accounts in the organization (see README for more details) | `bool` | `false` | no |
153+
| <a name="input_excluded_account_ids"></a> [excluded\_account\_ids](#input\_excluded\_account\_ids) | List of account IDs to exclude from Inspector enablement when enable\_inspector\_for\_all\_accounts is true | `list(string)` | `[]` | no |
154154
| <a name="input_inspector_name"></a> [inspector\_name](#input\_inspector\_name) | Name prefix for Inspector-related resources | `string` | `"inspector"` | no |
155155
| <a name="input_is_delegated_admin"></a> [is\_delegated\_admin](#input\_is\_delegated\_admin) | Whether this account is a delegated administrator | `bool` | `false` | no |
156156
| <a name="input_resource_types"></a> [resource\_types](#input\_resource\_types) | List of resource types to be scanned | `list(string)` | <pre>[<br> "EC2",<br> "ECR",<br> "LAMBDA"<br>]</pre> | no |

main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ locals {
66
account_ids = var.enable_inspector_for_all_accounts ? [
77
for account in data.aws_organizations_organization.this.accounts :
88
account.id
9-
if account.id != data.aws_caller_identity.this.account_id
9+
if account.id != data.aws_caller_identity.this.account_id &&
10+
!contains(var.excluded_account_ids, account.id)
1011
] : var.accounts_to_associate_with_inspector
1112
}
13+
1214
resource "aws_inspector2_enabler" "this" {
1315
count = var.enable_inspector ? 1 : 0
1416

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,9 @@ variable "accounts_to_associate_with_inspector" {
8080
description = "List of AWS account IDs to associate with Inspector (used for more granular control over which accounts are associated with Inspector; see README for more details)"
8181
type = list(string)
8282
}
83+
84+
variable "excluded_account_ids" {
85+
description = "List of account IDs to exclude from Inspector enablement when enable_inspector_for_all_accounts is true"
86+
type = list(string)
87+
default = []
88+
}

0 commit comments

Comments
 (0)