Skip to content

Commit 8411cad

Browse files
authored
feat: attach extra iam policies (#37)
> adds datadog-core-attach-extras, a simple feature to just allow extra policies to be attached to the core integration role. we've been using this for like over 6 months in a fork with the datadog s3 log archive functionality, which uses the same role as the core integration & requires some extra s3 permissions. > i'm not personally aware of other similarish cases where the core role would need some extra permissions, but if there are any then this can be used for those too
1 parent dcd8521 commit 8411cad

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

logs_monitoring.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
resource aws_cloudformation_stack "datadog-forwarder" {
1+
resource "aws_cloudformation_stack" "datadog-forwarder" {
22
name = "${local.stack_prefix}datadog-forwarder"
33
capabilities = ["CAPABILITY_IAM", "CAPABILITY_NAMED_IAM", "CAPABILITY_AUTO_EXPAND"]
44
parameters = {
@@ -18,13 +18,13 @@ resource aws_cloudformation_stack "datadog-forwarder" {
1818
}
1919
}
2020

21-
resource aws_secretsmanager_secret "datadog_api_key" {
21+
resource "aws_secretsmanager_secret" "datadog_api_key" {
2222
name_prefix = "${local.stack_prefix}datadog-api-key"
2323
description = "Datadog API Key"
2424
tags = local.default_tags
2525
}
2626

27-
resource aws_secretsmanager_secret_version "datadog_api_key" {
27+
resource "aws_secretsmanager_secret_version" "datadog_api_key" {
2828
secret_id = aws_secretsmanager_secret.datadog_api_key.id
2929
secret_string = var.datadog_api_key
3030
}

logs_monitoring_cloudwatch_log.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ resource "aws_cloudwatch_log_subscription_filter" "test_lambdafunction_logfilter
77
distribution = "Random"
88
}
99

10-
resource aws_lambda_permission "allow_cloudwatch_logs_to_call_dd_lambda_handler" {
10+
resource "aws_lambda_permission" "allow_cloudwatch_logs_to_call_dd_lambda_handler" {
1111
count = length(var.cloudwatch_log_groups)
1212
statement_id = "${replace(var.cloudwatch_log_groups[count.index], "/", "_")}-AllowExecutionFromCloudWatchLogs"
1313
action = "lambda:InvokeFunction"

main.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,9 @@ resource "aws_iam_role_policy_attachment" "datadog-core-attach" {
141141
role = aws_iam_role.datadog-integration[0].name
142142
policy_arn = aws_iam_policy.datadog-core[0].arn
143143
}
144+
145+
resource "aws_iam_role_policy_attachment" "datadog-core-attach-extras" {
146+
for_each = toset(var.extra_policy_arns)
147+
role = aws_iam_role.datadog-integration[0].name
148+
policy_arn = each.value
149+
}

vars.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ variable "env" {
4949
}
5050
variable "account_specific_namespace_rules" {
5151
description = "account_specific_namespace_rules argument for datadog_integration_aws resource"
52-
type = map
52+
type = map(any)
5353
default = {}
5454
}
5555
variable "elb_logs_bucket_prefix" {
@@ -86,3 +86,9 @@ variable "filter_tags" {
8686
type = list(string)
8787
default = []
8888
}
89+
90+
variable "extra_policy_arns" {
91+
description = "Extra policy arns to attach to the datadog-integration-role"
92+
type = list(string)
93+
default = []
94+
}

0 commit comments

Comments
 (0)