i am trying to develop generic terraform modules to support data-dog monitors and let the user of the modules to append resources and/or override resources in side generic modules.
terraform overrides feature works fine without modules, But not working when using modules.
how to override some of the resource parameters inside modules?
Requirements:
/modules/datadog/monitors.tf contains list of resources, each resource represents a generic datadog monitor with default parameter values. Each individual application may choose to override one or more parameters inside each resource.
/application-1/monitors.tf contains module with source as /modules/datadog/ , some more monitors that are not covered in generic monitors and some variables.
/application-1/monitors.tf
module "datadog" {
source = "/modules/datadog/"
}
/modules/datadog/monitors.tf
# Generic Datadog monitor to monitor cpu
resource "datadog_monitor" "foo" {
name = "Name for monitor foo"
type = "metric alert"
message = "Monitor triggered. Notify: @hipchat-channel"
escalation_message = "Escalation message @pagerduty"
query = "avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo} by {host} > 4"
thresholds {
ok = 0
warning = 2
warning_recovery = 1
critical = 4
critical_recovery = 3
}
notify_no_data = false
renotify_interval = 60
notify_audit = false
timeout_h = 60
include_tags = true
silenced {
"*" = 0
}
tags = ["foo:bar", "baz"]
}
Solution 1: Add overrides.tf to /modules/datadog Directory. terraform override feature merges content in overrides.tf to
configuration defined in monitors.tf.
But the problem with this solution is each application specific overrides.tf needs to be copied over to /modules/datadog Directory before running apply command.
overrides.tf
resource "datadog_monitor" "foo" {
escalation_message = "Escalation message @pagerduty1"
thresholds {
ok = 0
warning = 20
warning_recovery = 10
critical = 40
critical_recovery = 35
}
notify_no_data = false
}
Solution 2: can i use overrides with modules? i tried to override resource parameters by copying overrides.tf to /application-1/ Directory, But terraform is not overriding resources, instead it is considering both as different resources.