使用 Terraform import 命令获取 Datadog 监控信息
这是什么
我想您可能需要已部署监视器的TF代码信息,
以下是摘要。
我想也许用terraformer命令获取更为常见,但这次我尝试使用terraform import命令获取。
由于这仅仅是备忘录,如果您需要作为参考,请以阅读官方文件等副读材料的感觉为愿望。
准备之前
我在 init.tf 中写了一些关于密钥的信息。
provider "datadog" {
api_key = ""
app_key = ""
}
我立刻执行
参考或参照命令,尝试执行此命令及其参数。可以从以下链接查看更多信息:
https://registry.terraform.io/providers/DataDog/datadog/latest/docs/resources/monitor#import
$ terraform import datadog_monitor."Datadog Monitor Name" "Datadog Monitor ID"
出现了错误。
$ terraform import datadog_monitor."ec2-error-test" "Datadog Monitor ID"
Error: resource address "datadog_monitor.ec2-error-test" does not exist in the configuration.
Before importing this resource, please create its configuration in the root module. For example:
resource "datadog_monitor" "ec2-error-test" {
# (resource arguments)
}
因为有一种被要求以这种感觉随意地首先写出来的感觉,所以我随意地创建了一个tf文件,并进行以下记录。
resource "datadog_monitor" "ec2-error-test" {
# (resource arguments)
}
通過了再次执行。
$ terraform import datadog_monitor."ec2-error-test" "Datadog Monitor ID"
datadog_monitor.ec2-error-test: Importing from ID "Datadog Monitor ID"...
datadog_monitor.ec2-error-test: Import complete!
Imported datadog_monitor
datadog_monitor.ec2-error-test: Refreshing state... [id=Datadog Monitor ID]
Import successful!
The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.
在我的情况下,tfstate.tf以这样的方式进行了输出。
~中略~
"name": "ec2-error-test",
"new_host_delay": 0,
"no_data_timeframe": 0,
"notify_audit": false,
"notify_no_data": false,
"priority": 0,
"query": ”hogehoge”,
"renotify_interval": 0,
"require_full_window": false,
"restricted_roles": [],
"silenced": {
"*": 0
},
"tags": [],
"threshold_windows": null,
"thresholds": null,
"timeout_h": 0,
"type": "log alert",
"validate": null
请提供以下参考资料的中文原生释义,仅需要一种选项:
参考
· https://htnosm.hatenablog.com/entry/2017/05/08/090000
· https://www.terraform.io/cli/import
· https://www.terraform.io/cli/commands/import
· https://www.terraform.io/cli/import/usage
· https://www.terraform.io/plugin/sdkv2/resources/import
· https://registry.terraform.io/providers/DataDog/datadog/latest/docs/resources/monitor#import
· https://htnosm.hatenablog.com/entry/2017/05/08/090000
· https://www.terraform.io/cli/import
· https://www.terraform.io/cli/commands/import
· https://www.terraform.io/cli/import/usage
· https://www.terraform.io/plugin/sdkv2/resources/import
· https://registry.terraform.io/providers/DataDog/datadog/latest/docs/resources/monitor#import
我参考了您的意见。非常感谢您。