generated from gfkse/template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
iam.tf
91 lines (76 loc) · 2.68 KB
/
iam.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
resource "aws_iam_role" "datadog_task_execution_role" {
name = "${var.resource_prefix}_datadog_task_execution_role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Sid = ""
Principal = {
Service = "ecs-tasks.amazonaws.com"
}
},
]
})
tags = var.tags
}
resource "aws_iam_role_policy_attachment" "aws_managed_ecs_task_execution_policy_attachment" {
role = aws_iam_role.datadog_task_execution_role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
}
resource "aws_iam_policy" "datadog_task_execution_role_policy" {
count = var.dd_api_encryption_kms_key_id == "" || var.dd_api_encryption_kms_key_id == null ? 1 : 0
name = "${var.resource_prefix}_datadog_task_execution_role_policy"
path = "/"
description = "Ensures to have the needed execution permissions for datadog task."
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"ssm:GetParameters",
"secretsmanager:GetSecretValue",
"kms:Decrypt"
]
Resource = [
local.dd_api_key_param_arn
]
},
]
})
}
resource "aws_iam_role_policy_attachment" "datadog_tasks_execution_role_policy_attachment" {
count = var.dd_api_encryption_kms_key_id == "" || var.dd_api_encryption_kms_key_id == null ? 1 : 0
role = aws_iam_role.datadog_task_execution_role.name
policy_arn = aws_iam_policy.datadog_task_execution_role_policy[0].arn
}
resource "aws_iam_policy" "datadog_task_execution_role_policy_with_kms_key" {
count = var.dd_api_encryption_kms_key_id != "" && var.dd_api_encryption_kms_key_id != null ? 1 : 0
name = "${var.resource_prefix}_datadog_task_execution_role_policy_with_kms_key"
path = "/"
description = "Ensures to have the needed execution permissions for datadog task."
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"ssm:GetParameters",
"secretsmanager:GetSecretValue",
"kms:Decrypt"
]
Resource = [
local.dd_api_key_param_arn,
local.dd_api_enc_kms_key_arn
]
},
]
})
}
resource "aws_iam_role_policy_attachment" "datadog_tasks_execution_role_policy_attachment_with_kms_key" {
count = var.dd_api_encryption_kms_key_id != "" && var.dd_api_encryption_kms_key_id != null ? 1 : 0
role = aws_iam_role.datadog_task_execution_role.name
policy_arn = aws_iam_policy.datadog_task_execution_role_policy_with_kms_key[0].arn
}