How do I get a reference to that monitor that was/will be created? I need to provide the Datadog ID, clearly, not the TF id of the resource … How do I establish the relationship?
while I haven’t tested this, I think MonitorId: monitor.Id() could be it. The id property is not necessarily Terraform specific but rather depends on the resource.
# datadog_monitor.errors will be created
+ resource "datadog_monitor" "errors" {
...
}
# datadog_downtime.errors_downtime will be created
+ resource "datadog_downtime" "errors_downtime" {
+ monitor_id = (known after apply)
...
}
(and if the monitor already exists, the monitor_id for the downtime resource is correctly grabbed from the state file (it’s a number, the ID of the monitor in Datadog)
To do something similar with the CDK in Golang, I have to do something like this:
// the TF resource IDs/names
monitorId := "errors"
downtimeId := "errors_downtime"
// the monitor
myMonitor := datadogMonitor.NewMonitor(*stack, &monitorId, &monitorConfig)
// myMonitor.Id() is a *string
// and I need a *float for the downtime `monitor_id` field
floatId, _ := strconv.ParseFloat(*myMonitor.Id(), 64)
datadogMonitorDowntime.NewDowntime(*stack, &downtimeId,
&datadogMonitorDowntime.DowntimeConfig{
MonitorId: &floatId,
...
}
)
but I think that myMonitor.Id() returns errors, not the ID in the Datadog world of the monitor that will be created.
// the TF resource IDs/names
monitorId := "errors"
downtimeId := "errors_downtime"
// the monitor
myMonitor := datadogMonitor.NewMonitor(*stack, &monitorId, &monitorConfig)
then myMonitor.Id() resolves to an internal “token”, something like "#{TOKEN[TOKEN.1]}". Using the Token functionality, I can ask CDKTF to resolve the value (during synth) to the actual Id of the monitor that is created: