Generating configuration from remote state is still not officially supported by Terraform.
However, when I stupidly enough deleted a complex DataDog resource that I had created manually, I managed to fully restore it and create a full terraform file for it using a few simple commands
This worked for me with the datadog_synthetics_test
resource, so this will be the example resource below.
If this works for you with any other Terraform resources, I would love to know 🤗 .
Terraform and provider versions:
❯ tf -version
Terraform v1.1.2
on darwin_arm64
+ provider registry.terraform.io/datadog/datadog v3.12.0
resource "datadog_synthetics_test" "my_test" {
}
2. Import the resource into local terraform state - docs.
terraform import datadog_synthetics_test.my_test <RESOURCE_ID>
terraform state show -no-color datadog_synthetics_test.my_test > my_test.tf
resource "datadog_synthetics_test" "my_test" {
# id = "***-***-***"
# monitor_id = ******
.
.
.
}
terraform apply my_test.tf
Voilà!
Resource creates successfully