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

fix(inspector is now enabled on deploy) #914

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions modules/aws-inspector2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ components:
| Name | Type |
|------|------|
| [aws_inspector2_delegated_admin_account.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/inspector2_delegated_admin_account) | resource |
| [aws_inspector2_enabler.delegated_admin](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/inspector2_enabler) | resource |
| [aws_inspector2_enabler.member_accounts](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/inspector2_enabler) | resource |
| [aws_inspector2_member_association.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/inspector2_member_association) | resource |
| [aws_inspector2_organization_configuration.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/inspector2_organization_configuration) | resource |
| [aws_caller_identity.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
Expand Down
20 changes: 20 additions & 0 deletions modules/aws-inspector2/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ locals {

create_org_delegation = local.enabled && local.is_org_management_account
create_org_configuration = local.enabled && local.is_org_delegated_administrator_account && var.admin_delegated

resource_types = compact([var.auto_enable_ec2 ? "EC2" : null, var.auto_enable_ecr ? "ECR" : null, var.auto_enable_lambda ? "Lambda" : null])
}

data "aws_caller_identity" "this" {
Expand All @@ -26,17 +28,35 @@ resource "aws_inspector2_delegated_admin_account" "default" {
account_id = local.org_delegated_administrator_account_id
}

resource "aws_inspector2_enabler" "delegated_admin" {
count = local.create_org_configuration ? 1 : 0

account_ids = [local.org_delegated_administrator_account_id]
resource_types = local.resource_types
}

# If we are are in the AWS Organization designated administrator account,
# configure all other accounts to send their Inspector2 findings.
resource "aws_inspector2_organization_configuration" "default" {
count = local.create_org_configuration ? 1 : 0

depends_on = [aws_inspector2_enabler.delegated_admin]
auto_enable {
ec2 = var.auto_enable_ec2
ecr = var.auto_enable_ecr
lambda = var.auto_enable_lambda
}
}

resource "aws_inspector2_enabler" "member_accounts" {
count = local.create_org_configuration ? 1 : 0

depends_on = [aws_inspector2_member_association.default]

account_ids = local.member_account_ids
resource_types = local.resource_types
}

resource "aws_inspector2_member_association" "default" {
for_each = local.create_org_configuration ? toset(local.member_account_ids) : []
account_id = each.value
Expand Down
Loading