Skip to content

Commit 8d84f1b

Browse files
authored
Merge pull request #244 from terraform-contrib/feat/insights/allow-enabling-available-insights
feat(insights): allow enabling available insights
2 parents 7248e47 + 4f4fd69 commit 8d84f1b

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.DS_Store
22
.terraform
3+
.terraform.lock.hcl
34
terraform.tfstate
45
terraform.tfstate.backup
56
terraform.tfstate.*.backup

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ No modules.
6161

6262
| Name | Description | Type | Default | Required |
6363
|------|-------------|------|---------|:--------:|
64+
| api\_call\_rate\_insight | A measurement of write-only management API calls that occur per minute against a baseline API call volume. | `bool` | `false` | no |
65+
| api\_error\_rate\_insight | A measurement of management API calls that result in error codes. The error is shown if the API call is unsuccessful. | `bool` | `false` | no |
6466
| cloudwatch\_log\_group\_name | The name of the CloudWatch Log Group that receives CloudTrail events. | `string` | `"cloudtrail-events"` | no |
6567
| enabled | Enables logging for the trail. Defaults to true. Setting this to false will pause logging. | `bool` | `true` | no |
6668
| iam\_policy\_name | Name for the CloudTrail IAM policy | `string` | `"cloudtrail-cloudwatch-logs-policy"` | no |

main.tf

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
# The AWS region currently being used.
2-
data "aws_region" "current" {
3-
}
2+
data "aws_region" "current" {}
43

54
# The AWS account id
6-
data "aws_caller_identity" "current" {
7-
}
5+
data "aws_caller_identity" "current" {}
86

97
# The AWS partition (commercial or govcloud)
108
data "aws_partition" "current" {}
@@ -219,12 +217,11 @@ data "aws_iam_policy_document" "cloudtrail_kms_policy_doc" {
219217
"kms:Decrypt*",
220218
"kms:ReEncrypt*",
221219
"kms:GenerateDataKey*",
222-
"kms:Describe*"
220+
"kms:Describe*",
223221
]
224222
resources = ["*"]
225223
}
226224

227-
228225
statement {
229226
sid = "Allow Cloudtrail to decrypt and generate key for sns access"
230227
effect = "Allow"
@@ -240,7 +237,6 @@ data "aws_iam_policy_document" "cloudtrail_kms_policy_doc" {
240237
]
241238
resources = ["*"]
242239
}
243-
244240
}
245241

246242
resource "aws_kms_key" "cloudtrail" {
@@ -289,8 +285,18 @@ resource "aws_cloudtrail" "main" {
289285
# Enables SNS log notification
290286
sns_topic_name = var.sns_topic_arn
291287

292-
tags = var.tags
288+
# Enable Insights
289+
dynamic "insight_selector" {
290+
for_each = compact([
291+
var.api_call_rate_insight ? "ApiCallRateInsight" : null,
292+
var.api_error_rate_insight ? "ApiErrorRateInsight" : null,
293+
])
294+
content {
295+
insight_type = insight_selector.value
296+
}
297+
}
293298

299+
tags = var.tags
294300

295301
depends_on = [
296302
aws_kms_key.cloudtrail,

variables.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ variable "s3_key_prefix" {
5656
default = "cloudtrail"
5757
type = string
5858
}
59+
5960
variable "sns_topic_arn" {
6061
description = "ARN of the SNS topic for notification of log file delivery."
6162
default = ""
@@ -67,3 +68,15 @@ variable "tags" {
6768
default = {}
6869
type = map(string)
6970
}
71+
72+
variable "api_call_rate_insight" {
73+
description = "A measurement of write-only management API calls that occur per minute against a baseline API call volume."
74+
default = false
75+
type = bool
76+
}
77+
78+
variable "api_error_rate_insight" {
79+
description = "A measurement of management API calls that result in error codes. The error is shown if the API call is unsuccessful."
80+
default = false
81+
type = bool
82+
}

0 commit comments

Comments
 (0)