Skip to content

Commit a381429

Browse files
nmueschtherve
andauthored
Add FAQ about terraformer (DataDog#9201)
* Add faq about terraformer * Apply suggestions from code review Co-authored-by: Thomas Hervé <thomas.herve@datadoghq.com> * Add section about generation Co-authored-by: Thomas Hervé <thomas.herve@datadoghq.com>
1 parent 098be99 commit a381429

File tree

2 files changed

+105
-18
lines changed

2 files changed

+105
-18
lines changed

content/en/integrations/faq/_index.md

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -113,29 +113,33 @@ aliases:
113113

114114
* [For SNMP, does Datadog have a list of commonly used/compatible OIDs? ][48]
115115

116+
## Terraform
117+
118+
* [How to import datadog resources into Terraform][49]
119+
116120
## Unix
117121

118-
* [How can I gather metrics from the UNIX shell?][49]
122+
* [How can I gather metrics from the UNIX shell?][50]
119123

120124
## Vertica
121125

122-
* [How to collect metrics from custom Vertica queries][50]
126+
* [How to collect metrics from custom Vertica queries][51]
123127

124128
## VMWare
125129

126-
* [Can I limit the number of VMs that are pulled in via the VMWare integration?][51]
130+
* [Can I limit the number of VMs that are pulled in via the VMWare integration?][52]
127131

128132
## Webhooks
129133

130-
* [How to make a Trello Card using Webhooks][52]
134+
* [How to make a Trello Card using Webhooks][53]
131135

132136
## Windows
133137

134-
* [How to add event log files to the `Win32_NTLogEvent` WMI class][53]
135-
* [Collect Custom Windows Performance Counters over WMI][54]
136-
* [Windows Status Based Check][55]
137-
* [How to monitor events from the Windows Event Logs][56]
138-
* [How to retrieve WMI metrics][57]
138+
* [How to add event log files to the `Win32_NTLogEvent` WMI class][54]
139+
* [Collect Custom Windows Performance Counters over WMI][55]
140+
* [Windows Status Based Check][56]
141+
* [How to monitor events from the Windows Event Logs][57]
142+
* [How to retrieve WMI metrics][58]
139143

140144
[1]: /integrations/faq/aws-integration-and-cloudwatch-faq/
141145
[2]: /integrations/faq/how-do-i-pull-my-ec2-tags-without-using-the-aws-integration/
@@ -185,12 +189,13 @@ aliases:
185189
[46]: /integrations/faq/tagging-rabbitmq-queues-by-tag-family/
186190
[47]: /integrations/faq/redis-integration-error-unknown-command-config/
187191
[48]: /integrations/faq/for-snmp-does-datadog-have-a-list-of-commonly-used-compatible-oids/
188-
[49]: https://github.com/DataDog/Miscellany/tree/master/custom_check_shell
189-
[50]: /integrations/faq/how-to-collect-metrics-from-custom-vertica-queries/
190-
[51]: /integrations/faq/can-i-limit-the-number-of-vms-that-are-pulled-in-via-the-vmware-integration/
191-
[52]: /integrations/faq/how-to-make-trello-card-using-webhooks/
192-
[53]: /integrations/faq/how-to-add-event-log-files-to-the-win32-ntlogevent-wmi-class/
193-
[54]: /integrations/faq/collect-custom-windows-performance-counters-over-wmi/
194-
[55]: /integrations/faq/windows-status-based-check/
195-
[56]: /integrations/faq/how-to-monitor-events-from-the-windows-event-logs/
196-
[57]: /integrations/faq/how-to-retrieve-wmi-metrics/
192+
[49]: /integrations/faq/how-to-import-datadog-resources-into-terraform/
193+
[50]: https://github.com/DataDog/Miscellany/tree/master/custom_check_shell
194+
[51]: /integrations/faq/how-to-collect-metrics-from-custom-vertica-queries/
195+
[52]: /integrations/faq/can-i-limit-the-number-of-vms-that-are-pulled-in-via-the-vmware-integration/
196+
[53]: /integrations/faq/how-to-make-trello-card-using-webhooks/
197+
[54]: /integrations/faq/how-to-add-event-log-files-to-the-win32-ntlogevent-wmi-class/
198+
[55]: /integrations/faq/collect-custom-windows-performance-counters-over-wmi/
199+
[56]: /integrations/faq/windows-status-based-check/
200+
[57]: /integrations/faq/how-to-monitor-events-from-the-windows-event-logs/
201+
[58]: /integrations/faq/how-to-retrieve-wmi-metrics/
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
title: Importing Datadog Resources into Terraform
3+
kind: faq
4+
---
5+
6+
## Overview
7+
8+
Terraform supports an out-of-the-box way to import existing resources into your terraform state via the [`terraform import`][1] command.
9+
This can be done via the `terraform import <resource_type>.<resource_name> <existing_id>`.
10+
11+
This approach is `state only` and requires already having the HCL resource fully defined in your terraform configuration files. To import the configuration fully, you can use a tool like Terraformer.
12+
13+
## Terraformer
14+
15+
The [terraformer project][2] allows you to import a resource as both state and HCL configuration.
16+
17+
Once installed, you can setup a terraform directory with a basic `main.tf`
18+
19+
This uses terraform 0.13+ syntax, but you can find more configurations on the [official datadog provider docs][3]
20+
21+
```hcl
22+
# main.tf
23+
24+
terraform {
25+
required_providers {
26+
datadog = {
27+
source = "DataDog/datadog"
28+
}
29+
}
30+
}
31+
32+
# Configure the Datadog provider
33+
provider "datadog" {
34+
api_key = var.datadog_api_key
35+
app_key = var.datadog_app_key
36+
}
37+
38+
variable "datadog_api_key" {
39+
default = "<YOUR_API_KEY>"
40+
}
41+
42+
variable "datadog_app_key" {
43+
default = "<YOUR_APPLICATION_KEY>"
44+
}
45+
```
46+
47+
Then run `terraform init` from within this directory to pull the datadog terraform provider.
48+
49+
Now you can use `terraformer` to start importing resources. For example, to import Dashboard `abc-def-ghi` you can run
50+
51+
`terraformer import datadog --resources=dashboard --filter=dashboard=abc-def-ghi --api-key <YOUR_API_KEY> --app-key <YOUR_APP_KEY>`
52+
53+
This generates a folder `generated` that contains both a terraform state file, as well as HCL terraform config files representing the imported resource.
54+
55+
```
56+
generated
57+
└── datadog
58+
└── dashboard
59+
├── dashboard.tf
60+
├── outputs.tf
61+
├── provider.tf
62+
└── terraform.tfstate
63+
```
64+
65+
* `dashboard.tf`: The HCL configuration file for the newly imported dashboard
66+
* `outputs.tf`: An HCL containing outputs to use potentially in other configurations
67+
* `provider.tf`: An HCL initialization of the provider, similar to whats in our `main.tf` file
68+
* `terraform.tfstate`: The terraform state representing the imported dashboard
69+
70+
## Other examples of running terraformer
71+
72+
All example commands require the `--api-key` and `--app-key` flags.
73+
74+
* Import all monitors: `terraformer import datadog --resources=monitor`
75+
* Import monitor with id 1234: `terraformer import datadog --resources=monitor --filter=monitor=1234`
76+
* Import monitors with id 1234 and 1234: `terraformer import datadog --resources=monitor --filter=monitor=1234:12345`
77+
* Import all monitors and dashboards: `terraformer import datadog --resources=monitor,dashboard`
78+
* Import monitor with id 1234 and dashboard with id abc-def-ghi: `terraformer import datadog --resources=monitor,dashboard --filter=monitor=1234,dashboard=abc-def-ghi`
79+
80+
[1]: https://www.terraform.io/docs/import/index.html
81+
[2]: https://github.com/GoogleCloudPlatform/terraformer
82+
[3]: https://registry.terraform.io/providers/DataDog/datadog/latest/docs

0 commit comments

Comments
 (0)