Skip to content

Commit

Permalink
feat: attach extra iam policies (#37)
Browse files Browse the repository at this point in the history
> 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
  • Loading branch information
bcha authored Aug 25, 2021
1 parent dcd8521 commit 8411cad
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
6 changes: 3 additions & 3 deletions logs_monitoring.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource aws_cloudformation_stack "datadog-forwarder" {
resource "aws_cloudformation_stack" "datadog-forwarder" {
name = "${local.stack_prefix}datadog-forwarder"
capabilities = ["CAPABILITY_IAM", "CAPABILITY_NAMED_IAM", "CAPABILITY_AUTO_EXPAND"]
parameters = {
Expand All @@ -18,13 +18,13 @@ resource aws_cloudformation_stack "datadog-forwarder" {
}
}

resource aws_secretsmanager_secret "datadog_api_key" {
resource "aws_secretsmanager_secret" "datadog_api_key" {
name_prefix = "${local.stack_prefix}datadog-api-key"
description = "Datadog API Key"
tags = local.default_tags
}

resource aws_secretsmanager_secret_version "datadog_api_key" {
resource "aws_secretsmanager_secret_version" "datadog_api_key" {
secret_id = aws_secretsmanager_secret.datadog_api_key.id
secret_string = var.datadog_api_key
}
2 changes: 1 addition & 1 deletion logs_monitoring_cloudwatch_log.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ resource "aws_cloudwatch_log_subscription_filter" "test_lambdafunction_logfilter
distribution = "Random"
}

resource aws_lambda_permission "allow_cloudwatch_logs_to_call_dd_lambda_handler" {
resource "aws_lambda_permission" "allow_cloudwatch_logs_to_call_dd_lambda_handler" {
count = length(var.cloudwatch_log_groups)
statement_id = "${replace(var.cloudwatch_log_groups[count.index], "/", "_")}-AllowExecutionFromCloudWatchLogs"
action = "lambda:InvokeFunction"
Expand Down
6 changes: 6 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,9 @@ resource "aws_iam_role_policy_attachment" "datadog-core-attach" {
role = aws_iam_role.datadog-integration[0].name
policy_arn = aws_iam_policy.datadog-core[0].arn
}

resource "aws_iam_role_policy_attachment" "datadog-core-attach-extras" {
for_each = toset(var.extra_policy_arns)
role = aws_iam_role.datadog-integration[0].name
policy_arn = each.value
}
8 changes: 7 additions & 1 deletion vars.tf
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ variable "env" {
}
variable "account_specific_namespace_rules" {
description = "account_specific_namespace_rules argument for datadog_integration_aws resource"
type = map
type = map(any)
default = {}
}
variable "elb_logs_bucket_prefix" {
Expand Down Expand Up @@ -86,3 +86,9 @@ variable "filter_tags" {
type = list(string)
default = []
}

variable "extra_policy_arns" {
description = "Extra policy arns to attach to the datadog-integration-role"
type = list(string)
default = []
}

0 comments on commit 8411cad

Please sign in to comment.