Hello.
Recently CloudWatch Alarm get a new feature - Anomaly Detection.
More information here - https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Anomaly_Detection.html
Will you be able to add this feature?
# Copy-paste your Terraform configurations here - for large Terraform configs,
# please use a service like Dropbox and share a link to the ZIP file. For
# security, you can also encrypt the files using our GPG public key.
I was able to get the expected config by configuring the alarm manually and running plan
:
resource "aws_cloudwatch_metric_alarm" "MyApiRequestCount" {
alarm_name = "MyApiRequestCount"
comparison_operator = "GreaterThanUpperThreshold"
evaluation_periods = "2"
datapoints_to_alarm = "2"
threshold = "0"
metric_query {
id = "m1"
metric {
metric_name = "RequestCount"
namespace = "AWS/ApplicationELB"
period = "300"
stat = "Sum"
dimensions = {
LoadBalancer = "app/MyApi/..."
}
}
}
metric_query {
id = "ad1"
label = "RequestCount (expected)"
return_data = true
expression = "ANOMALY_DETECTION_BAND(m1, 2)"
}
treat_missing_data = "missing"
alarm_description = "Too many incoming requests"
alarm_actions = []
ok_actions = []
}
I then ran apply
and got my state files in sync with no actual changes to the infrastructure.
The only issue is that currently this CloudWatch feature doesn't seem to be working correctly - it doesn't change the alarm status when the conditions are met. I can see the metric going outside the band on the graph, but this never results in an ALARM status. Not an issue with terraform though - this happens with manually-configured alarms.
@dskrvk when running terraform apply
you will run into an error because the following value in the ThresholdMetricId
value not being set in the API:
Error: Creating metric alarm failed: ValidationError: Metric expression must evaluate to a single time series
status code: 400, request id: 0f5e3a11-ac17-4fe6-86d5-f7b52cc898e3
on Terraform/cloudwatch_buckets.tf line 1, in resource "aws_cloudwatch_metric_alarm" "bucket_name":
1: resource "aws_cloudwatch_metric_alarm" "bucket_name" {
I guess this issue will be resolved by setting threshold_metric_id
after https://github.com/terraform-providers/terraform-provider-aws/pull/9828 is merged.
@apparentlymart whenever you get a second could you poke someone about this PR on Monday?
I hate to be "that guy", but this is blocking a monitoring story in my sprint. I am just about to throw my monitor in CloudFormation and call the stack creation via Terraform, but I really don't want to add tech debt to my future workload.
What are we waiting on? As discussed in the PR this CloudWatch functionality is now "Generally Available". Who do we need to get involved in this PR?
I also need this and it appears we have some duplicate issues being created.
I'm also "blocked" by this feature. I"m deploying a bunch of lambdas that use cloudwatch, and we have to manually update them after the deployment.
Please note that we are using this issue to track the aws_cloudwatch_metric_alarm
enhancement for anomaly detection in CloudWatch. There is also now a separate feature request for an aws_cloudwatch_anomaly_detector
resource at #10551. I will update this issue title accordingly.
Support for this functionality in the aws_cloudwatch_metric_alarm
resource has been merged and will release with version 2.40.0 of the Terraform AWS Provider, next week. Thanks to @hakopako for the implementation. 👍
This has been released in version 2.40.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.
For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!
I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.
If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!
Most helpful comment
@dskrvk when running
terraform apply
you will run into an error because the following value in theThresholdMetricId
value not being set in the API:I guess this issue will be resolved by setting
threshold_metric_id
after https://github.com/terraform-providers/terraform-provider-aws/pull/9828 is merged.@apparentlymart whenever you get a second could you poke someone about this PR on Monday?