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

Add CloudTrail Advanced Event Selector #70

Merged
merged 11 commits into from
Apr 15, 2024
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ Available targets:
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_additional_tag_map"></a> [additional\_tag\_map](#input\_additional\_tag\_map) | Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`.<br>This is for some rare cases where resources want additional configuration of tags<br>and therefore take a list of maps with tag key, value, and additional configuration. | `map(string)` | `{}` | no |
| <a name="input_advanced_event_selector"></a> [advanced\_event\_selector](#input\_advanced\_event\_selector) | Specifies an advanced event selector for enabling data event logging. See: https://www.terraform.io/docs/providers/aws/r/cloudtrail.html for details on this variable | <pre>list(object({<br> field_selector = list(object({<br> field = string<br> equals = optional(list(string))<br> not_equals = optional(list(string))<br> starts_with = optional(list(string))<br> not_starts_with = optional(list(string))<br> ends_with = optional(list(string))<br> not_ends_with = optional(list(string))<br> }))<br> name = optional(string)<br> }))</pre> | `[]` | no |
| <a name="input_attributes"></a> [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,<br>in the order they appear in the list. New attributes are appended to the<br>end of the list. The elements of the list are joined by the `delimiter`<br>and treated as a single ID element. | `list(string)` | `[]` | no |
| <a name="input_cloud_watch_logs_group_arn"></a> [cloud\_watch\_logs\_group\_arn](#input\_cloud\_watch\_logs\_group\_arn) | Specifies a log group name using an Amazon Resource Name (ARN), that represents the log group to which CloudTrail logs will be delivered | `string` | `""` | no |
| <a name="input_cloud_watch_logs_role_arn"></a> [cloud\_watch\_logs\_role\_arn](#input\_cloud\_watch\_logs\_role\_arn) | Specifies the role for the CloudWatch Logs endpoint to assume to write to a user’s log group | `string` | `""` | no |
Expand Down
1 change: 1 addition & 0 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_additional_tag_map"></a> [additional\_tag\_map](#input\_additional\_tag\_map) | Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`.<br>This is for some rare cases where resources want additional configuration of tags<br>and therefore take a list of maps with tag key, value, and additional configuration. | `map(string)` | `{}` | no |
| <a name="input_advanced_event_selector"></a> [advanced\_event\_selector](#input\_advanced\_event\_selector) | Specifies an advanced event selector for enabling data event logging. See: https://www.terraform.io/docs/providers/aws/r/cloudtrail.html for details on this variable | <pre>list(object({<br> field_selector = list(object({<br> field = string<br> equals = optional(list(string))<br> not_equals = optional(list(string))<br> starts_with = optional(list(string))<br> not_starts_with = optional(list(string))<br> ends_with = optional(list(string))<br> not_ends_with = optional(list(string))<br> }))<br> name = optional(string)<br> }))</pre> | `[]` | no |
| <a name="input_attributes"></a> [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,<br>in the order they appear in the list. New attributes are appended to the<br>end of the list. The elements of the list are joined by the `delimiter`<br>and treated as a single ID element. | `list(string)` | `[]` | no |
| <a name="input_cloud_watch_logs_group_arn"></a> [cloud\_watch\_logs\_group\_arn](#input\_cloud\_watch\_logs\_group\_arn) | Specifies a log group name using an Amazon Resource Name (ARN), that represents the log group to which CloudTrail logs will be delivered | `string` | `""` | no |
| <a name="input_cloud_watch_logs_role_arn"></a> [cloud\_watch\_logs\_role\_arn](#input\_cloud\_watch\_logs\_role\_arn) | Specifies the role for the CloudWatch Logs endpoint to assume to write to a user’s log group | `string` | `""` | no |
Expand Down
2 changes: 1 addition & 1 deletion examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module "cloudtrail" {

module "cloudtrail_s3_bucket" {
source = "cloudposse/cloudtrail-s3-bucket/aws"
version = "0.14.0"
version = "0.26.3"

force_destroy = true

Expand Down
22 changes: 21 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,24 @@ resource "aws_cloudtrail" "default" {
}
}
}
}

dynamic "advanced_event_selector" {
for_each = var.advanced_event_selector
content {
name = lookup(advanced_event_selector.value, "name", null)

dynamic "field_selector" {
for_each = advanced_event_selector.value.field_selector
content {
field = field_selector.value.field
equals = lookup(field_selector.value, "equals", null)
not_equals = lookup(field_selector.value, "not_equals", null)
starts_with = lookup(field_selector.value, "starts_with", null)
not_starts_with = lookup(field_selector.value, "not_starts_with", null)
ends_with = lookup(field_selector.value, "ends_with", null)
not_ends_with = lookup(field_selector.value, "not_ends_with", null)
}
}
}
}
}
17 changes: 17 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,23 @@ variable "event_selector" {
default = []
}

variable "advanced_event_selector" {
type = list(object({
field_selector = list(object({
field = string
equals = optional(list(string))
not_equals = optional(list(string))
starts_with = optional(list(string))
not_starts_with = optional(list(string))
ends_with = optional(list(string))
not_ends_with = optional(list(string))
}))
name = optional(string)
}))
description = "Specifies an advanced event selector for enabling data event logging. See: https://www.terraform.io/docs/providers/aws/r/cloudtrail.html for details on this variable"
default = []
}

variable "kms_key_arn" {
type = string
description = "Specifies the KMS key ARN to use to encrypt the logs delivered by CloudTrail"
Expand Down