generated from geekcell/terraform-aws-module-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
166 lines (154 loc) · 5.09 KB
/
main.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/**
* # Terraform AWS DataDog Module
*
* Terraform module that helps with various Datadog AWS integrations. This module consists of the Main module
* for creating the AWS Integration role and the following submodules:
*
* ### Metric collection
* * Metric polling (out of the box with integration role)
* * [Metric streams with Kinesis Firehose](./modules/metric_streams/README.md)
*
* ### Resource collection
* * Cloud Security Posture Management (can be enabled via the integration role)
*
* ### [ECS Fargate Agent:](./modules/fargate_agent/README.md)
* * Scrape DB metrics for DBM
*
* ### [Log Forwarder Lambda:](./modules/log_forwarder/README.md)
* * Forward any S3 or CloudWatch logs to Datadog
*/
data "aws_caller_identity" "current" {
count = var.aws_account_id == null ? 1 : 0
}
locals {
datadog_integration_role_name = "${var.prefix}-datadog-integration"
}
resource "datadog_integration_aws" "main" {
account_id = coalesce(var.aws_account_id, data.aws_caller_identity.current[0].id)
role_name = local.datadog_integration_role_name
account_specific_namespace_rules = var.account_specific_namespace_rules
excluded_regions = var.excluded_regions
filter_tags = var.filter_tags
host_tags = var.host_tags
cspm_resource_collection_enabled = var.cspm_resource_collection_enabled
metrics_collection_enabled = var.metrics_collection_enabled
resource_collection_enabled = var.resource_collection_enabled
}
module "integration_role" {
source = "geekcell/iam-role/aws"
version = ">= 1.0.0, < 2.0.0"
name = local.datadog_integration_role_name
use_name_prefix = false
description = "Role for Datadog AWS Integration"
policy_arns = [module.integration_policy.arn]
assume_roles = {
"AWS" : {
sid = "TrustDatadog"
identifiers = ["arn:aws:iam::${var.datadog_aws_account_id}:root"]
conditions = [
{
test = "StringEquals"
variable = "sts:ExternalId"
values = [datadog_integration_aws.main.external_id]
}
]
}
}
}
module "integration_policy" {
source = "geekcell/iam-policy/aws"
version = ">= 1.0.0, < 2.0.0"
name = "${var.prefix}-datadog-integration"
description = "Policy for Datadog AWS Integration"
statements = [
{
sid = "BucketList"
effect = "Allow"
actions = [
"apigateway:GET",
"autoscaling:Describe*",
"backup:List*",
"budgets:ViewBudget",
"cloudfront:GetDistributionConfig",
"cloudfront:ListDistributions",
"cloudtrail:DescribeTrails",
"cloudtrail:GetTrailStatus",
"cloudtrail:LookupEvents",
"cloudwatch:Describe*",
"cloudwatch:Get*",
"cloudwatch:List*",
"codedeploy:List*",
"codedeploy:BatchGet*",
"directconnect:Describe*",
"dynamodb:List*",
"dynamodb:Describe*",
"ec2:Describe*",
"ecs:Describe*",
"ecs:List*",
"elasticache:Describe*",
"elasticache:List*",
"elasticfilesystem:DescribeFileSystems",
"elasticfilesystem:DescribeTags",
"elasticfilesystem:DescribeAccessPoints",
"elasticloadbalancing:Describe*",
"elasticmapreduce:List*",
"elasticmapreduce:Describe*",
"es:ListTags",
"es:ListDomainNames",
"es:DescribeElasticsearchDomains",
"events:CreateEventBus",
"fsx:DescribeFileSystems",
"fsx:ListTagsForResource",
"health:DescribeEvents",
"health:DescribeEventDetails",
"health:DescribeAffectedEntities",
"kinesis:List*",
"kinesis:Describe*",
"kms:GetKeyRotationStatus",
"lambda:GetPolicy",
"lambda:List*",
"logs:DeleteSubscriptionFilter",
"logs:DescribeLogGroups",
"logs:DescribeLogStreams",
"logs:DescribeSubscriptionFilters",
"logs:FilterLogEvents",
"logs:PutSubscriptionFilter",
"logs:TestMetricFilter",
"organizations:Describe*",
"organizations:List*",
"rds:Describe*",
"rds:List*",
"redshift:DescribeClusters",
"redshift:DescribeLoggingStatus",
"route53:List*",
"s3:GetBucketLogging",
"s3:GetBucketLocation",
"s3:GetBucketNotification",
"s3:GetBucketTagging",
"s3:ListAllMyBuckets",
"s3:PutBucketNotification",
"ses:Get*",
"sns:List*",
"sns:Publish",
"sqs:ListQueues",
"states:ListStateMachines",
"states:DescribeStateMachine",
"support:DescribeTrustedAdvisor*",
"support:RefreshTrustedAdvisorCheck",
"tag:GetResources",
"tag:GetTagKeys",
"tag:GetTagValues",
"wafv2:GetLoggingConfiguration",
"xray:BatchGetTraces",
"xray:GetTraceSummaries",
]
resources = ["*"]
}
]
tags = var.tags
}
resource "aws_iam_role_policy_attachment" "csp" {
count = var.cspm_resource_collection_enabled ? 1 : 0
role = module.integration_role.name
policy_arn = "arn:aws:iam::aws:policy/SecurityAudit"
}