Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1ae2aeb

Browse files
authoredJun 5, 2025··
Merge pull request #40 from sourcefuse/fix/inspector-member-acct-association
Fix/inspector member acct association
2 parents bed2c42 + 4c3219e commit 1ae2aeb

File tree

13 files changed

+131
-58
lines changed

13 files changed

+131
-58
lines changed
 

‎.github/workflows/terratest.yaml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
name: Terratest
3+
on: # yamllint disable-line rule:truthy
4+
pull_request:
5+
types: [opened]
6+
workflow_dispatch:
7+
inputs:
8+
pr_number:
9+
description: 'Pull Request Number'
10+
required: true
11+
12+
permissions:
13+
id-token: write
14+
contents: read
15+
statuses: write # Required for setting commit status
16+
17+
jobs:
18+
terratest:
19+
runs-on: ubuntu-latest
20+
name: Terratest Checks
21+
22+
env:
23+
PR_NUMBER: >-
24+
${{ github.event_name == 'workflow_dispatch' &&
25+
github.event.inputs.pr_number || github.event.pull_request.number }}
26+
27+
28+
steps:
29+
- name: Checkout PR code
30+
uses: actions/checkout@v4
31+
with:
32+
ref: refs/pull/${{ env.PR_NUMBER }}/head
33+
34+
- name: Configure AWS credentials via OIDC
35+
uses: aws-actions/configure-aws-credentials@v2
36+
with:
37+
role-to-assume: ${{ secrets.ARC_IAC_TERRATEST_ROLE }}
38+
aws-region: us-east-1
39+
40+
- name: Set up Go
41+
uses: actions/setup-go@v4
42+
with:
43+
go-version: '1.24'
44+
45+
- name: Set up Terraform
46+
uses: hashicorp/setup-terraform@v2
47+
with:
48+
terraform_version: 1.5.7
49+
terraform_wrapper: false
50+
51+
- name: Create test directory and download go from S3
52+
run: |
53+
mkdir -p terra-test
54+
aws s3 cp ${{ secrets.ARC_TERRATEST_GO_FILE }} terra-test/terra_test.go
55+
- name: Initialize Go module and install dependencies
56+
run: |
57+
cd terra-test
58+
ls
59+
go mod init terraform-test || true
60+
go get github.com/gruntwork-io/terratest/modules/terraform
61+
go get github.com/stretchr/testify/assert
62+
go mod tidy
63+
go test -v -timeout 40m
64+
- name: Report check status manually
65+
uses: actions/github-script@v7
66+
with:
67+
github-token: ${{ secrets.GITHUB_TOKEN }}
68+
script: |
69+
const pr_number = parseInt(process.env.PR_NUMBER);
70+
const pr = await github.rest.pulls.get({
71+
owner: context.repo.owner,
72+
repo: context.repo.repo,
73+
pull_number: pr_number,
74+
});
75+
const sha = pr.data.head.sha;
76+
await github.rest.repos.createCommitStatus({
77+
owner: context.repo.owner,
78+
repo: context.repo.repo,
79+
sha: sha,
80+
state: 'success',
81+
context: 'terratest',
82+
description: 'Manual terratest completed successfully',
83+
target_url:
84+
`https://github.com/${context.repo.owner}/${context.repo.repo}` +
85+
`/actions/runs/${process.env.GITHUB_RUN_ID}`,
86+
});
File renamed without changes.

‎README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ module "cloud_security" {
5353

5454
| Name | Version |
5555
|------|---------|
56-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3, < 2.0.0 |
56+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5.0 |
5757
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0, < 6.0 |
5858

5959
## Providers
6060

6161
| Name | Version |
6262
|------|---------|
63-
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.62.0 |
63+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.99.1 |
6464

6565
## Modules
6666

@@ -98,6 +98,7 @@ module "cloud_security" {
9898

9999
| Name | Description | Type | Default | Required |
100100
|------|-------------|------|---------|:--------:|
101+
| <a name="input_add_inspector_member_accounts"></a> [add\_inspector\_member\_accounts](#input\_add\_inspector\_member\_accounts) | Whether to associate as a member account with your Amazon Inspector delegated administrator account. | `bool` | `false` | no |
101102
| <a name="input_aws_config_managed_rules"></a> [aws\_config\_managed\_rules](#input\_aws\_config\_managed\_rules) | A list of AWS Managed Rules that should be enabled on the account.<br><br>See the following for a list of possible rules to enable:<br>https://docs.aws.amazon.com/config/latest/developerguide/managed-rules-by-aws-config.html | <pre>map(object({<br> description = string<br> identifier = string<br> input_parameters = any<br> tags = map(string)<br> enabled = bool<br> }))</pre> | `{}` | no |
102103
| <a name="input_aws_config_sns_subscribers"></a> [aws\_config\_sns\_subscribers](#input\_aws\_config\_sns\_subscribers) | A map of subscription configurations for SNS topics<br><br>For more information, see:<br>https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic_subscription#argument-reference<br><br>protocol:<br> The protocol to use. The possible values for this are: sqs, sms, lambda, application. (http or https are partially<br> supported, see link) (email is an option but is unsupported in terraform, see link).<br>endpoint:<br> The endpoint to send data to, the contents will vary with the protocol. (see link for more information)<br>endpoint\_auto\_confirms:<br> Boolean indicating whether the end point is capable of auto confirming subscription e.g., PagerDuty. Default is<br> false<br>raw\_message\_delivery:<br> Boolean indicating whether or not to enable raw message delivery (the original message is directly passed, not wrapped in JSON with the original message in the message property).<br> Default is false | <pre>map(object({<br> protocol = string<br> endpoint = string<br> endpoint_auto_confirms = bool<br> raw_message_delivery = bool<br> }))</pre> | n/a | yes |
103104
| <a name="input_create_config_iam_role"></a> [create\_config\_iam\_role](#input\_create\_config\_iam\_role) | Flag to indicate whether an iam role should be created for aws config. | `bool` | `false` | no |

‎example/data.tf

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1 @@
1-
data "aws_ssm_parameter" "guard_duty" {
2-
name = "/${var.namespace}/${var.environment}/guard-duty/opsgenie/api-key"
3-
}
4-
5-
data "aws_ssm_parameter" "security_hub" {
6-
name = "/${var.namespace}/${var.environment}/security-hub/opsgenie/api-key"
7-
}
8-
9-
data "aws_ssm_parameter" "aws_config" {
10-
name = "/${var.namespace}/${var.environment}/aws-config/opsgenie/api-key"
11-
}
1+
data "aws_caller_identity" "current" {}

‎example/dev.tfvars renamed to ‎example/dev.auto.tfvars

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
region = "us-east-1"
2-
environment = "dev"
2+
environment = "poc"
33
namespace = "arc"
44
project = "aws-modules"
55

@@ -19,6 +19,4 @@ aws_config_managed_rules = {
1919
}
2020
}
2121

22-
create_inspector_iam_role = true
23-
inspector_enabled_rules = ["cis"]
2422
inspector_schedule_expression = "rate(7 days)"

‎example/locals.tf

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,39 @@
11
locals {
22
aws_config_sns_subscribers = {
33
opsgenie = {
4-
protocol = "https"
5-
endpoint = data.aws_ssm_parameter.aws_config.value
4+
protocol = "email"
5+
endpoint = "devops-team@example.com"
66
endpoint_auto_confirms = true
77
raw_message_delivery = false
88
}
99
}
1010
guard_duty_sns_subscribers = {
1111
opsgenie = {
12-
protocol = "https"
13-
endpoint = data.aws_ssm_parameter.guard_duty.value
12+
protocol = "email"
13+
endpoint = "devops-team@example.com"
1414
endpoint_auto_confirms = true
1515
raw_message_delivery = false
1616
}
1717
}
1818
security_hub_sns_subscribers = {
1919
opsgenie = {
20-
protocol = "https"
21-
endpoint = data.aws_ssm_parameter.security_hub.value
20+
protocol = "email"
21+
endpoint = "devops-team@example.com"
2222
endpoint_auto_confirms = true
2323
raw_message_delivery = false
2424
}
2525
}
2626

27+
inspector_sns_subscribers = {
28+
opsgenie = {
29+
protocol = "email"
30+
endpoint = "devops-team@example.com"
31+
endpoint_auto_confirms = true
32+
raw_message_delivery = false
33+
}
34+
}
35+
36+
2737
security_hub_standards = [
2838
"standards/aws-foundational-security-best-practices/v/1.0.0",
2939
"standards/cis-aws-foundations-benchmark/v/1.4.0"

‎example/main.tf

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
## defaults
33
################################################################################
44
terraform {
5-
required_version = "~> 1.7"
5+
required_version = ">= 1.5.0"
66

77
required_providers {
88
aws = {
@@ -32,8 +32,7 @@ module "tags" {
3232

3333

3434
module "cloud_security" {
35-
source = "sourcefuse/arc-security/aws"
36-
version = "0.0.5"
35+
source = "../"
3736

3837
region = var.region
3938
environment = var.environment
@@ -53,10 +52,10 @@ module "cloud_security" {
5352
aws_config_managed_rules = var.aws_config_managed_rules
5453
enabled_security_hub_standards = local.security_hub_standards
5554

56-
create_inspector_iam_role = var.create_inspector_iam_role
57-
inspector_enabled_rules = var.inspector_enabled_rules
58-
inspector_schedule_expression = var.inspector_schedule_expression
59-
inspector_assessment_event_subscription = var.inspector_assessment_event_subscription
55+
56+
inspector_schedule_expression = var.inspector_schedule_expression
57+
inspector_account_list = [data.aws_caller_identity.current.account_id]
58+
inspector_sns_subscribers = local.inspector_sns_subscribers
6059

6160
tags = module.tags.tags
6261
}

‎example/variables.tf

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,12 @@ variable "project" {
2323
default = ""
2424
}
2525

26-
############################################################################
27-
## security hub
28-
############################################################################
29-
variable "create_inspector_iam_role" {
30-
description = "Toggle to create aws inspector iam role"
31-
type = bool
32-
default = true
33-
}
34-
35-
variable "inspector_enabled_rules" {
36-
description = "list of rules to pass to inspector"
37-
type = list(string)
38-
default = []
39-
}
40-
4126
variable "inspector_schedule_expression" {
4227
description = "AWS Schedule Expression to indicate how often the inspector scheduled event shoud run"
4328
type = string
4429
default = "rate(7 days)"
4530
}
4631

47-
variable "inspector_assessment_event_subscription" {
48-
description = "Configures sending notifications about a specified assessment template event to a designated SNS topic"
49-
type = map(object({
50-
event = string
51-
topic_arn = string
52-
}))
53-
default = {}
54-
}
55-
5632
variable "aws_config_managed_rules" {
5733
description = <<-DOC
5834
A list of AWS Managed Rules that should be enabled on the account.

‎main.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ module "inspector" {
8181

8282
enable_inspector_at_orgnanization = var.enable_inspector_at_orgnanization
8383

84-
account_list = var.inspector_account_list
85-
resource_types = var.inspector_resource_types
86-
subscribers = var.inspector_sns_subscribers
84+
account_list = var.inspector_account_list
85+
add_inspector_member_accounts = var.add_inspector_member_accounts
86+
resource_types = var.inspector_resource_types
87+
subscribers = var.inspector_sns_subscribers
8788

8889
}

‎modules/inspector/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ resource "aws_inspector2_organization_configuration" "this" {
2020
}
2121

2222
resource "aws_inspector2_member_association" "this" {
23-
for_each = toset(var.account_list)
23+
for_each = var.add_inspector_member_accounts ? toset(var.account_list) : toset([])
2424
account_id = each.value
2525
}
2626

‎modules/inspector/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ variable "enable_inspector_at_orgnanization" {
44
default = false
55
}
66

7+
variable "add_inspector_member_accounts" {
8+
type = bool
9+
description = "Whether to associate as a member account with your Amazon Inspector delegated administrator account."
10+
default = false
11+
}
12+
713
variable "account_list" {
814
type = list(string)
915
description = "List of Account for which inspector has to be enabled"

‎variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,12 @@ variable "inspector_schedule_expression" {
216216
default = "rate(7 days)"
217217
}
218218

219+
variable "add_inspector_member_accounts" {
220+
type = bool
221+
description = "Whether to associate as a member account with your Amazon Inspector delegated administrator account."
222+
default = false
223+
}
224+
219225
variable "inspector_sns_subscribers" {
220226
type = map(object({
221227
protocol = string

‎versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
## defaults
33
################################################################################
44
terraform {
5-
required_version = ">= 1.3, < 2.0.0"
5+
required_version = ">= 1.5.0"
66

77
required_providers {
88
aws = {

0 commit comments

Comments
 (0)
Please sign in to comment.