Skip to content

Commit a870a45

Browse files
committed
feat(aws): rework AWS integration for Datadog
1 parent 5e782cc commit a870a45

File tree

11 files changed

+181
-143
lines changed

11 files changed

+181
-143
lines changed

cloud/aws/README.md

Lines changed: 19 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,27 @@ module "datadog-integrations-cloud-aws" {
77
source = "claranet/integrations/datadog//cloud/aws"
88
version = "{revision}"
99
10-
aws_account = var.aws_account
10+
aws_account_id = var.aws_account
11+
env = var.environment
1112
}
1213
1314
```
1415

16+
<!-- BEGIN_TF_DOCS -->
1517
## Requirements
1618

1719
| Name | Version |
1820
|------|---------|
19-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.12.31 |
20-
| <a name="requirement_datadog"></a> [datadog](#requirement\_datadog) | >= 3.0.0 |
21+
| terraform | >= 1.11 |
22+
| aws | >= 6.0.0 |
23+
| datadog | >= 3.0.0 |
2124

2225
## Providers
2326

2427
| Name | Version |
2528
|------|---------|
26-
| <a name="provider_aws"></a> [aws](#provider\_aws) | n/a |
27-
| <a name="provider_datadog"></a> [datadog](#provider\_datadog) | >= 3.0.0 |
29+
| aws | >= 6.0.0 |
30+
| datadog | >= 3.0.0 |
2831

2932
## Modules
3033

@@ -37,59 +40,26 @@ No modules.
3740
| [aws_iam_policy.dd_integration_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
3841
| [aws_iam_policy_attachment.allow_dd_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy_attachment) | resource |
3942
| [aws_iam_role.dd_integration_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
40-
| [datadog_integration_aws.datadog_integration_aws](https://registry.terraform.io/providers/Datadog/datadog/latest/docs/resources/integration_aws) | resource |
43+
| [datadog_integration_aws_account.main](https://registry.terraform.io/providers/Datadog/datadog/latest/docs/resources/integration_aws_account) | resource |
4144
| [aws_iam_policy_document.datadog_integration_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
4245
| [aws_iam_policy_document.dd_trust_relationship](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
46+
| [datadog_integration_aws_external_id.main](https://registry.terraform.io/providers/Datadog/datadog/latest/docs/data-sources/integration_aws_external_id) | data source |
4347

4448
## Inputs
4549

4650
| Name | Description | Type | Default | Required |
4751
|------|-------------|------|---------|:--------:|
48-
| <a name="input_account_specific_namespace_rules"></a> [account\_specific\_namespace\_rules](#input\_account\_specific\_namespace\_rules) | Namespaces to limit metric collection for datadog aws integration | `map` | `{}` | no |
49-
| <a name="input_aws_account"></a> [aws\_account](#input\_aws\_account) | n/a | `any` | n/a | yes |
50-
| <a name="input_datadog_aws_account_id"></a> [datadog\_aws\_account\_id](#input\_datadog\_aws\_account\_id) | AWS account\_id of Datadog | `string` | `"464622532012"` | no |
51-
| <a name="input_filter_tags"></a> [filter\_tags](#input\_filter\_tags) | Filters tags to limit metrics collection on EC2 for datadog aws integration | `list` | <pre>[<br> "dd_monitoring:enabled"<br>]</pre> | no |
52-
| <a name="input_host_tags"></a> [host\_tags](#input\_host\_tags) | Tags to add all metrics retrieved from the datadog aws integration | `list` | `[]` | no |
52+
| aws\_account\_id | AWS account configuration for Datadog integration | `string` | n/a | yes |
53+
| aws\_iam\_role\_enabled | Enable IAM role deployment for Datadog AWS integration | `bool` | `false` | no |
54+
| datadog\_aws\_account\_id | AWS account\_id of Datadog | `string` | `"464622532012"` | no |
55+
| env | Environment configuration for Datadog integration | `string` | n/a | yes |
56+
| metrics\_config | Metrics configuration for Datadog AWS integration | <pre>object({<br> automute_enabled : optional(bool, true),<br> collect_cloudwatch_alarms : optional(bool, false),<br> collect_custom_metrics : optional(bool, false),<br> enabled : optional(bool, true),<br> namespace_filters : optional(object({<br> exclude_only : optional(list(string), null),<br> include_only : optional(list(string), null),<br> }), {<br> exclude_only = ["AWS/ElasticMapReduce", "AWS/SQS", "AWS/Usage"]<br> }),<br> tag_filters : optional(object({<br> namespace : string,<br> tags : list(string),<br> }), {<br> namespace = "AWS/EC2"<br> tags = ["dd_monitored:true"]<br> }),<br> })</pre> | `{}` | no |
5357

5458
## Outputs
5559

5660
| Name | Description |
5761
|------|-------------|
58-
| <a name="output_aws_role_arn"></a> [aws\_role\_arn](#output\_aws\_role\_arn) | The role ARN of the DataDog integration |
59-
| <a name="output_aws_role_name"></a> [aws\_role\_name](#output\_aws\_role\_name) | The IAM role name of the DataDog integration |
60-
## Related documentation
61-
62-
DataDog documentation: [https://docs.datadoghq.com/integrations/amazon_web_services/#setup](https://docs.datadoghq.com/integrations/amazon_web_services/#setup)
63-
64-
## Requirements
65-
66-
You need to configure you AWS provider.
67-
Credentials could be set in your `terraform.tfvars`.
68-
69-
```
70-
variable "aws_region" {
71-
type = string
72-
}
73-
74-
variable "aws_account" {
75-
type = string
76-
}
77-
78-
variable "aws_access_key" {
79-
}
80-
81-
variable "aws_secret_key" {
82-
}
83-
84-
variable "aws_token" {
85-
}
86-
87-
provider "aws" {
88-
region = var.aws_region
89-
access_key = var.aws_access_key
90-
secret_key = var.aws_secret_key
91-
token = var.aws_token
92-
}
93-
94-
```
95-
62+
| aws\_integration\_id | The ID of the DataDog AWS integration |
63+
| aws\_role\_arn | The role ARN of the DataDog integration |
64+
| aws\_role\_name | The IAM role name of the DataDog integration |
65+
<!-- END_TF_DOCS -->

cloud/aws/inputs.tf

Lines changed: 0 additions & 24 deletions
This file was deleted.

cloud/aws/integrations-aws.tf

Lines changed: 0 additions & 8 deletions
This file was deleted.

cloud/aws/locals.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
locals {
22
role_name = "DatadogAWSIntegrationRole"
33
}
4-

cloud/aws/outputs.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
output "aws_role_arn" {
22
description = "The role ARN of the DataDog integration"
3-
value = aws_iam_role.dd_integration_role.arn
3+
value = try(aws_iam_role.dd_integration_role.arn, null)
44
}
55

66
output "aws_role_name" {
77
description = "The IAM role name of the DataDog integration"
8-
value = aws_iam_role.dd_integration_role.name
8+
value = try(aws_iam_role.dd_integration_role.name, null)
99
}
1010

11+
output "aws_integration_id" {
12+
description = "The ID of the DataDog AWS integration"
13+
value = datadog_integration_aws_account.main.id
14+
}
Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,68 @@
1+
data "datadog_integration_aws_external_id" "main" {
2+
aws_account_id = var.aws_account_id
3+
4+
lifecycle {
5+
enabled = var.aws_iam_role_enabled
6+
}
7+
}
8+
9+
resource "aws_iam_role" "dd_integration_role" {
10+
name = local.role_name
11+
description = "Datadog AWS Integration Role according to https://docs.datadoghq.com/integrations/aws"
12+
13+
assume_role_policy = data.aws_iam_policy_document.dd_trust_relationship.json
14+
15+
lifecycle {
16+
enabled = var.aws_iam_role_enabled
17+
}
18+
}
19+
20+
data "aws_iam_policy_document" "dd_trust_relationship" {
21+
statement {
22+
sid = "DatadogAWSTrustRelationship"
23+
effect = "Allow"
24+
actions = ["sts:AssumeRole"]
25+
26+
principals {
27+
type = "AWS"
28+
29+
identifiers = [
30+
"arn:aws:iam::${var.datadog_aws_account_id}:root",
31+
]
32+
}
33+
34+
condition {
35+
test = "StringEquals"
36+
values = [data.datadog_integration_aws_external_id.main.external_id]
37+
variable = "sts:ExternalId"
38+
}
39+
}
40+
41+
lifecycle {
42+
enabled = var.aws_iam_role_enabled
43+
}
44+
}
45+
46+
resource "aws_iam_policy_attachment" "allow_dd_role" {
47+
name = "Allow Datadog PolicyAccess via Role"
48+
roles = [aws_iam_role.dd_integration_role.name]
49+
policy_arn = aws_iam_policy.dd_integration_policy.arn
50+
51+
lifecycle {
52+
enabled = var.aws_iam_role_enabled
53+
}
54+
}
55+
156
resource "aws_iam_policy" "dd_integration_policy" {
257
name = "DatadogAWSIntegrationPolicy"
358
path = "/"
459
description = "Datadog integration policy according to https://docs.datadoghq.com/integrations/aws/"
560

661
policy = data.aws_iam_policy_document.datadog_integration_policy.json
62+
63+
lifecycle {
64+
enabled = var.aws_iam_role_enabled
65+
}
766
}
867

968
data "aws_iam_policy_document" "datadog_integration_policy" {
@@ -12,6 +71,7 @@ data "aws_iam_policy_document" "datadog_integration_policy" {
1271
effect = "Allow"
1372

1473
actions = [
74+
"account:GetAccountInformation",
1575
"apigateway:GET",
1676
"autoscaling:Describe*",
1777
"budgets:ViewBudget",
@@ -84,5 +144,8 @@ data "aws_iam_policy_document" "datadog_integration_policy" {
84144

85145
resources = ["*"]
86146
}
87-
}
88147

148+
lifecycle {
149+
enabled = var.aws_iam_role_enabled
150+
}
151+
}

cloud/aws/r-integration.tf

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
resource "datadog_integration_aws_account" "main" {
2+
account_tags = ["env:${var.env}"]
3+
aws_account_id = var.aws_account_id
4+
aws_partition = "aws"
5+
6+
aws_regions {
7+
include_all = true
8+
}
9+
10+
auth_config {
11+
aws_auth_config_role {
12+
role_name = local.role_name
13+
}
14+
}
15+
16+
metrics_config {
17+
automute_enabled = var.metrics_config.automute_enabled
18+
collect_cloudwatch_alarms = var.metrics_config.collect_cloudwatch_alarms
19+
collect_custom_metrics = var.metrics_config.collect_custom_metrics
20+
enabled = var.metrics_config.enabled
21+
namespace_filters {
22+
exclude_only = var.metrics_config.namespace_filters.exclude_only
23+
include_only = var.metrics_config.namespace_filters.include_only
24+
}
25+
dynamic "tag_filters" {
26+
for_each = var.metrics_config.tag_filters[*]
27+
content {
28+
namespace = tag_filters.value.namespace
29+
tags = tag_filters.value.tags
30+
}
31+
}
32+
}
33+
34+
resources_config {
35+
extended_collection = false
36+
}
37+
38+
logs_config {
39+
lambda_forwarder {}
40+
}
41+
traces_config {
42+
xray_services {}
43+
}
44+
}

cloud/aws/role.tf

Lines changed: 0 additions & 35 deletions
This file was deleted.

cloud/aws/test.tf.ci

Lines changed: 0 additions & 20 deletions
This file was deleted.

cloud/aws/variables.tf

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
variable "aws_account_id" {
2+
description = "AWS account configuration for Datadog integration"
3+
type = string
4+
}
5+
6+
variable "env" {
7+
description = "Environment configuration for Datadog integration"
8+
type = string
9+
}
10+
11+
variable "datadog_aws_account_id" {
12+
description = "AWS account_id of Datadog"
13+
type = string
14+
default = "464622532012"
15+
}
16+
17+
variable "metrics_config" {
18+
description = "Metrics configuration for Datadog AWS integration"
19+
type = object({
20+
automute_enabled : optional(bool, true),
21+
collect_cloudwatch_alarms : optional(bool, false),
22+
collect_custom_metrics : optional(bool, false),
23+
enabled : optional(bool, true),
24+
namespace_filters : optional(object({
25+
exclude_only : optional(list(string), null),
26+
include_only : optional(list(string), null),
27+
}), {
28+
exclude_only = ["AWS/ElasticMapReduce", "AWS/SQS", "AWS/Usage"]
29+
}),
30+
tag_filters : optional(object({
31+
namespace : string,
32+
tags : list(string),
33+
}), {
34+
namespace = "AWS/EC2"
35+
tags = ["dd_monitored:true"]
36+
}),
37+
})
38+
default = {}
39+
}
40+
41+
variable "aws_iam_role_enabled" {
42+
description = "Enable IAM role deployment for Datadog AWS integration"
43+
type = bool
44+
default = false
45+
}

0 commit comments

Comments
 (0)