Skip to content

Commit e327ebe

Browse files
authored
Rename datadog-aws-integration component to datadog-integration (cloudposse/terraform-aws-components#294)
0 parents  commit e327ebe

File tree

8 files changed

+312
-0
lines changed

8 files changed

+312
-0
lines changed

src/context.tf

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
#
2+
# ONLY EDIT THIS FILE IN github.com/cloudposse/terraform-null-label
3+
# All other instances of this file should be a copy of that one
4+
#
5+
#
6+
# Copy this file from https://github.com/cloudposse/terraform-null-label/blob/master/exports/context.tf
7+
# and then place it in your Terraform module to automatically get
8+
# Cloud Posse's standard configuration inputs suitable for passing
9+
# to Cloud Posse modules.
10+
#
11+
# Modules should access the whole context as `module.this.context`
12+
# to get the input variables with nulls for defaults,
13+
# for example `context = module.this.context`,
14+
# and access individual variables as `module.this.<var>`,
15+
# with final values filled in.
16+
#
17+
# For example, when using defaults, `module.this.context.delimiter`
18+
# will be null, and `module.this.delimiter` will be `-` (hyphen).
19+
#
20+
21+
module "this" {
22+
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.21.0"
23+
24+
enabled = var.enabled
25+
namespace = var.namespace
26+
environment = var.environment
27+
stage = var.stage
28+
name = var.name
29+
delimiter = var.delimiter
30+
attributes = var.attributes
31+
tags = var.tags
32+
additional_tag_map = var.additional_tag_map
33+
label_order = var.label_order
34+
regex_replace_chars = var.regex_replace_chars
35+
id_length_limit = var.id_length_limit
36+
37+
context = var.context
38+
}
39+
40+
# Copy contents of cloudposse/terraform-null-label/variables.tf here
41+
42+
variable "context" {
43+
type = object({
44+
enabled = bool
45+
namespace = string
46+
environment = string
47+
stage = string
48+
name = string
49+
delimiter = string
50+
attributes = list(string)
51+
tags = map(string)
52+
additional_tag_map = map(string)
53+
regex_replace_chars = string
54+
label_order = list(string)
55+
id_length_limit = number
56+
})
57+
default = {
58+
enabled = true
59+
namespace = null
60+
environment = null
61+
stage = null
62+
name = null
63+
delimiter = null
64+
attributes = []
65+
tags = {}
66+
additional_tag_map = {}
67+
regex_replace_chars = null
68+
label_order = []
69+
id_length_limit = null
70+
}
71+
description = <<-EOT
72+
Single object for setting entire context at once.
73+
See description of individual variables for details.
74+
Leave string and numeric variables as `null` to use default value.
75+
Individual variable settings (non-null) override settings in context object,
76+
except for attributes, tags, and additional_tag_map, which are merged.
77+
EOT
78+
}
79+
80+
variable "enabled" {
81+
type = bool
82+
default = null
83+
description = "Set to false to prevent the module from creating any resources"
84+
}
85+
86+
variable "namespace" {
87+
type = string
88+
default = null
89+
description = "Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp'"
90+
}
91+
92+
variable "environment" {
93+
type = string
94+
default = null
95+
description = "Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT'"
96+
}
97+
98+
variable "stage" {
99+
type = string
100+
default = null
101+
description = "Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release'"
102+
}
103+
104+
variable "name" {
105+
type = string
106+
default = null
107+
description = "Solution name, e.g. 'app' or 'jenkins'"
108+
}
109+
110+
variable "delimiter" {
111+
type = string
112+
default = null
113+
description = <<-EOT
114+
Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.
115+
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all.
116+
EOT
117+
}
118+
119+
variable "attributes" {
120+
type = list(string)
121+
default = []
122+
description = "Additional attributes (e.g. `1`)"
123+
}
124+
125+
variable "tags" {
126+
type = map(string)
127+
default = {}
128+
description = "Additional tags (e.g. `map('BusinessUnit','XYZ')`"
129+
}
130+
131+
variable "additional_tag_map" {
132+
type = map(string)
133+
default = {}
134+
description = "Additional tags for appending to tags_as_list_of_maps. Not added to `tags`."
135+
}
136+
137+
variable "label_order" {
138+
type = list(string)
139+
default = null
140+
description = <<-EOT
141+
The naming order of the id output and Name tag.
142+
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
143+
You can omit any of the 5 elements, but at least one must be present.
144+
EOT
145+
}
146+
147+
variable "regex_replace_chars" {
148+
type = string
149+
default = null
150+
description = <<-EOT
151+
Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`.
152+
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits.
153+
EOT
154+
}
155+
156+
variable "id_length_limit" {
157+
type = number
158+
default = null
159+
description = <<-EOT
160+
Limit `id` to this many characters.
161+
Set to `0` for unlimited length.
162+
Set to `null` for default, which is `0`.
163+
Does not affect `id_full`.
164+
EOT
165+
}
166+
167+
#### End of copy of cloudposse/terraform-null-label/variables.tf

src/default.auto.tfvars

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# This file is included by default in terraform plans
2+
3+
enabled = true

src/main.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module "datadog_integration" {
2+
source = "git::https://github.com/cloudposse/terraform-aws-datadog-integration.git?ref=tags/0.6.1"
3+
4+
datadog_aws_account_id = var.datadog_aws_account_id
5+
integrations = var.integrations
6+
filter_tags = var.filter_tags
7+
host_tags = var.host_tags
8+
excluded_regions = var.excluded_regions
9+
account_specific_namespace_rules = var.account_specific_namespace_rules
10+
11+
context = module.this.context
12+
}

src/outputs.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
output "aws_account_id" {
2+
value = module.datadog_integration.aws_account_id
3+
description = "AWS Account ID of the IAM Role for the Datadog integration"
4+
}
5+
6+
output "aws_role_name" {
7+
value = module.datadog_integration.aws_role_name
8+
description = "Name of the AWS IAM Role for the Datadog integration"
9+
}
10+
11+
output "datadog_external_id" {
12+
value = module.datadog_integration.datadog_external_id
13+
description = "Datadog integration external ID"
14+
}

src/providers.tf

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
provider "datadog" {
2+
api_key = data.aws_ssm_parameter.datadog_api_key.value
3+
app_key = data.aws_ssm_parameter.datadog_app_key.value
4+
}
5+
6+
provider "aws" {
7+
region = var.region
8+
9+
assume_role {
10+
# `terraform import` will not use data from a data source,
11+
# so on import we have to explicitly specify the role
12+
role_arn = coalesce(var.import_role_arn, module.iam_roles.terraform_role_arn)
13+
}
14+
}
15+
16+
module "iam_roles" {
17+
source = "../account-map/modules/iam-roles"
18+
stage = var.stage
19+
region = var.region
20+
}
21+
22+
variable "import_role_arn" {
23+
type = string
24+
default = null
25+
description = "IAM Role ARN to use when importing a resource"
26+
}

src/ssm.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
data "aws_ssm_parameter" "datadog_api_key" {
2+
name = format(var.ssm_parameter_name_format, var.ssm_path, "datadog_api_key")
3+
with_decryption = true
4+
}
5+
6+
data "aws_ssm_parameter" "datadog_app_key" {
7+
name = format(var.ssm_parameter_name_format, var.ssm_path, "datadog_app_key")
8+
with_decryption = true
9+
}
10+
11+
resource "aws_ssm_parameter" "datadog_aws_iam_role_name" {
12+
name = format(var.ssm_parameter_name_format, var.ssm_path, "datadog_aws_iam_role_name")
13+
description = "Name of the AWS IAM Role for Datadog to use for the integration"
14+
value = module.datadog_integration.aws_role_name
15+
type = "String"
16+
}

src/variables.tf

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
variable "region" {
2+
type = string
3+
description = "AWS Region"
4+
}
5+
6+
variable "datadog_aws_account_id" {
7+
type = string
8+
description = "The AWS account ID Datadog's integration servers use for all integrations"
9+
default = "464622532012"
10+
}
11+
12+
variable "integrations" {
13+
type = list(string)
14+
description = "List of AWS permission names to apply for different integrations (e.g. 'all', 'core')"
15+
default = ["all"]
16+
}
17+
18+
variable "filter_tags" {
19+
type = list(string)
20+
description = "An array of EC2 tags (in the form `key:value`) that defines a filter that Datadog use when collecting metrics from EC2. Wildcards, such as ? (for single characters) and * (for multiple characters) can also be used"
21+
default = null
22+
}
23+
24+
variable "host_tags" {
25+
type = list(string)
26+
description = "An array of tags (in the form `key:value`) to add to all hosts and metrics reporting through this integration"
27+
default = []
28+
}
29+
30+
variable "excluded_regions" {
31+
type = list(string)
32+
description = "An array of AWS regions to exclude from metrics collection"
33+
default = []
34+
}
35+
36+
variable "account_specific_namespace_rules" {
37+
type = map(string)
38+
description = "An object, (in the form {\"namespace1\":true/false, \"namespace2\":true/false} ), that enables or disables metric collection for specific AWS namespaces for this AWS account only"
39+
default = {}
40+
}
41+
42+
variable "ssm_parameter_name_format" {
43+
type = string
44+
default = "/%s/%s"
45+
description = "SSM parameter name format"
46+
}
47+
48+
variable "ssm_path" {
49+
type = string
50+
default = "datadog"
51+
description = "SSM path"
52+
}

src/versions.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
terraform {
2+
required_version = ">= 0.12"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 2.0"
8+
}
9+
template = {
10+
source = "hashicorp/template"
11+
version = ">= 2.0"
12+
}
13+
local = {
14+
source = "hashicorp/local"
15+
version = ">= 1.3"
16+
}
17+
datadog = {
18+
source = "DataDog/datadog"
19+
version = ">= 2.15.0"
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)