Skip to content

Commit 63f4578

Browse files
committed
Support unused access analyzer in access-analyzer
1 parent 61b285b commit 63f4578

File tree

5 files changed

+82
-13
lines changed

5 files changed

+82
-13
lines changed

modules/access-analyzer/README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ This module creates following resources.
1010

1111
| Name | Version |
1212
|------|---------|
13-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5 |
14-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.22 |
13+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.6 |
14+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.34 |
1515

1616
## Providers
1717

1818
| Name | Version |
1919
|------|---------|
20-
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.19.0 |
20+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.46.0 |
2121

2222
## Modules
2323

@@ -42,8 +42,10 @@ This module creates following resources.
4242
| <a name="input_resource_group_description"></a> [resource\_group\_description](#input\_resource\_group\_description) | (Optional) The description of Resource Group. | `string` | `"Managed by Terraform."` | no |
4343
| <a name="input_resource_group_enabled"></a> [resource\_group\_enabled](#input\_resource\_group\_enabled) | (Optional) Whether to create Resource Group to find and group AWS resources which are created by this module. | `bool` | `true` | no |
4444
| <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name) | (Optional) The name of Resource Group. A Resource Group name can have a maximum of 127 characters, including letters, numbers, hyphens, dots, and underscores. The name cannot start with `AWS` or `aws`. | `string` | `""` | no |
45+
| <a name="input_scope"></a> [scope](#input\_scope) | (Optional) A scope of Analyzer. Valid values are `ACCOUNT` or `ORGANIZATION`. Defaults to `ACCOUNT`. | `string` | `"ACCOUNT"` | no |
4546
| <a name="input_tags"></a> [tags](#input\_tags) | (Optional) A map of tags to add to all resources. | `map(string)` | `{}` | no |
46-
| <a name="input_type"></a> [type](#input\_type) | (Optional) Type of Analyzer. Valid values are `ACCOUNT` or `ORGANIZATION`. Defaults to `ACCOUNT`. | `string` | `"ACCOUNT"` | no |
47+
| <a name="input_type"></a> [type](#input\_type) | (Optional) A finding type of Analyzer. Valid values are `EXTERNAL_ACCESS` or `UNUSED_ACCESS`. Defaults to `EXTERNAL_ACCESS`. | `string` | `"EXTERNAL_ACCESS"` | no |
48+
| <a name="input_unused_access_tracking_period"></a> [unused\_access\_tracking\_period](#input\_unused\_access\_tracking\_period) | (Optional) A number of days for the tracking the period. Findings will be generated for access that hasn't been used in more than the specified number of days. Defaults to `90`. | `number` | `90` | no |
4749

4850
## Outputs
4951

@@ -53,5 +55,7 @@ This module creates following resources.
5355
| <a name="output_arn"></a> [arn](#output\_arn) | The Amazon Resource Name (ARN) of this Analyzer. |
5456
| <a name="output_id"></a> [id](#output\_id) | The ID of this Analyzer. |
5557
| <a name="output_name"></a> [name](#output\_name) | The name of the Analyzer. |
56-
| <a name="output_type"></a> [type](#output\_type) | The type of Analyzer. |
58+
| <a name="output_scope"></a> [scope](#output\_scope) | The scope of Analyzer. |
59+
| <a name="output_type"></a> [type](#output\_type) | The finding type of Analyzer. |
60+
| <a name="output_unused_access_tracking_period"></a> [unused\_access\_tracking\_period](#output\_unused\_access\_tracking\_period) | The scope of Analyzer. |
5761
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

modules/access-analyzer/main.tf

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,34 @@ locals {
1414
} : {}
1515
}
1616

17+
18+
###################################################
19+
# Access Analyzer
20+
###################################################
21+
1722
resource "aws_accessanalyzer_analyzer" "this" {
1823
analyzer_name = var.name
19-
type = var.type
24+
type = (var.type == "EXTERNAL_ACCESS"
25+
? var.scope
26+
: (var.type == "UNUSED_ACCESS"
27+
? "${var.scope}_UNUSED_ACCESS"
28+
: null
29+
)
30+
)
31+
32+
dynamic "configuration" {
33+
for_each = var.type == "UNUSED_ACCESS" ? ["go"] : []
34+
35+
content {
36+
dynamic "unused_access" {
37+
for_each = var.type == "UNUSED_ACCESS" ? ["go"] : []
38+
39+
content {
40+
unused_access_age = var.unused_access_tracking_period
41+
}
42+
}
43+
}
44+
}
2045

2146
tags = merge(
2247
{

modules/access-analyzer/outputs.tf

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,21 @@ output "arn" {
1414
}
1515

1616
output "type" {
17-
description = "The type of Analyzer."
18-
value = aws_accessanalyzer_analyzer.this.type
17+
description = "The finding type of Analyzer."
18+
value = var.type
19+
}
20+
21+
output "scope" {
22+
description = "The scope of Analyzer."
23+
value = var.scope
24+
}
25+
26+
output "unused_access_tracking_period" {
27+
description = "The scope of Analyzer."
28+
value = (var.type == "UNUSED_ACCESS"
29+
? one(aws_accessanalyzer_analyzer.this.configuration[0].unused_access[*].unused_access_age)
30+
: null
31+
)
1932
}
2033

2134
output "archive_rules" {

modules/access-analyzer/variables.tf

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,41 @@ variable "name" {
44
}
55

66
variable "type" {
7-
description = "(Optional) Type of Analyzer. Valid values are `ACCOUNT` or `ORGANIZATION`. Defaults to `ACCOUNT`."
7+
description = "(Optional) A finding type of Analyzer. Valid values are `EXTERNAL_ACCESS` or `UNUSED_ACCESS`. Defaults to `EXTERNAL_ACCESS`."
8+
type = string
9+
default = "EXTERNAL_ACCESS"
10+
nullable = false
11+
12+
validation {
13+
condition = contains(["EXTERNAL_ACCESS", "UNUSED_ACCESS"], var.type)
14+
error_message = "The `type` should be one of `EXTERNAL_ACCESS`, `UNUSED_ACCESS`."
15+
}
16+
}
17+
18+
variable "scope" {
19+
description = "(Optional) A scope of Analyzer. Valid values are `ACCOUNT` or `ORGANIZATION`. Defaults to `ACCOUNT`."
820
type = string
921
default = "ACCOUNT"
1022
nullable = false
1123

1224
validation {
13-
condition = contains(["ACCOUNT", "ORGANIZATION"], var.type)
14-
error_message = "The `type` should be one of `ACCOUNT`, `ORGANIZATION`."
25+
condition = contains(["ACCOUNT", "ORGANIZATION"], var.scope)
26+
error_message = "The `scope` should be one of `ACCOUNT`, `ORGANIZATION`."
27+
}
28+
}
29+
30+
variable "unused_access_tracking_period" {
31+
description = "(Optional) A number of days for the tracking the period. Findings will be generated for access that hasn't been used in more than the specified number of days. Defaults to `90`."
32+
type = number
33+
default = 90
34+
nullable = false
35+
36+
validation {
37+
condition = alltrue([
38+
var.unused_access_tracking_period >= 1,
39+
var.unused_access_tracking_period <= 180
40+
])
41+
error_message = "Valid value for `unused_access_tracking_period` is between 1 and 180."
1542
}
1643
}
1744

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
terraform {
2-
required_version = ">= 1.5"
2+
required_version = ">= 1.6"
33

44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 4.22"
7+
version = ">= 5.34"
88
}
99
}
1010
}

0 commit comments

Comments
 (0)