provider/aws: Add support for evaluate_low_sample_count_percentiles to cloudwatch_metric_alarm (#13371)
``` ```
This commit is contained in:
parent
815c085b8f
commit
6d9384aeeb
|
@ -105,6 +105,12 @@ func resourceAwsCloudWatchMetricAlarm() *schema.Resource {
|
||||||
Default: "missing",
|
Default: "missing",
|
||||||
ValidateFunc: validation.StringInSlice([]string{"breaching", "notBreaching", "ignore", "missing"}, true),
|
ValidateFunc: validation.StringInSlice([]string{"breaching", "notBreaching", "ignore", "missing"}, true),
|
||||||
},
|
},
|
||||||
|
"evaluate_low_sample_count_percentiles": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
ValidateFunc: validation.StringInSlice([]string{"evaluate", "ignore"}, true),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,6 +178,7 @@ func resourceAwsCloudWatchMetricAlarmRead(d *schema.ResourceData, meta interface
|
||||||
d.Set("unit", a.Unit)
|
d.Set("unit", a.Unit)
|
||||||
d.Set("extended_statistic", a.ExtendedStatistic)
|
d.Set("extended_statistic", a.ExtendedStatistic)
|
||||||
d.Set("treat_missing_data", a.TreatMissingData)
|
d.Set("treat_missing_data", a.TreatMissingData)
|
||||||
|
d.Set("evaluate_low_sample_count_percentiles", a.EvaluateLowSampleCountPercentile)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -248,6 +255,10 @@ func getAwsCloudWatchPutMetricAlarmInput(d *schema.ResourceData) cloudwatch.PutM
|
||||||
params.ExtendedStatistic = aws.String(v.(string))
|
params.ExtendedStatistic = aws.String(v.(string))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if v, ok := d.GetOk("evaluate_low_sample_count_percentiles"); ok {
|
||||||
|
params.EvaluateLowSampleCountPercentile = aws.String(v.(string))
|
||||||
|
}
|
||||||
|
|
||||||
var alarmActions []*string
|
var alarmActions []*string
|
||||||
if v := d.Get("alarm_actions"); v != nil {
|
if v := d.Get("alarm_actions"); v != nil {
|
||||||
for _, v := range v.(*schema.Set).List() {
|
for _, v := range v.(*schema.Set).List() {
|
||||||
|
|
|
@ -61,6 +61,33 @@ func TestAccAWSCloudWatchMetricAlarm_treatMissingData(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAWSCloudWatchMetricAlarm_evaluateLowSampleCountPercentiles(t *testing.T) {
|
||||||
|
var alarm cloudwatch.MetricAlarm
|
||||||
|
rInt := acctest.RandInt()
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckAWSCloudWatchMetricAlarmDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: testAccAWSCloudWatchMetricAlarmConfigTreatEvaluateLowSampleCountPercentiles(rInt),
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckCloudWatchMetricAlarmExists("aws_cloudwatch_metric_alarm.foobar", &alarm),
|
||||||
|
resource.TestCheckResourceAttr("aws_cloudwatch_metric_alarm.foobar", "evaluate_low_sample_count_percentiles", "evaluate"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Config: testAccAWSCloudWatchMetricAlarmConfigTreatEvaluateLowSampleCountPercentilesUpdated(rInt),
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckCloudWatchMetricAlarmExists("aws_cloudwatch_metric_alarm.foobar", &alarm),
|
||||||
|
resource.TestCheckResourceAttr("aws_cloudwatch_metric_alarm.foobar", "evaluate_low_sample_count_percentiles", "ignore"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccAWSCloudWatchMetricAlarm_extendedStatistic(t *testing.T) {
|
func TestAccAWSCloudWatchMetricAlarm_extendedStatistic(t *testing.T) {
|
||||||
var alarm cloudwatch.MetricAlarm
|
var alarm cloudwatch.MetricAlarm
|
||||||
rInt := acctest.RandInt()
|
rInt := acctest.RandInt()
|
||||||
|
@ -222,6 +249,46 @@ resource "aws_cloudwatch_metric_alarm" "foobar" {
|
||||||
}`, rInt)
|
}`, rInt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccAWSCloudWatchMetricAlarmConfigTreatEvaluateLowSampleCountPercentiles(rInt int) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
resource "aws_cloudwatch_metric_alarm" "foobar" {
|
||||||
|
alarm_name = "terraform-test-foobar%d"
|
||||||
|
comparison_operator = "GreaterThanOrEqualToThreshold"
|
||||||
|
evaluation_periods = "2"
|
||||||
|
metric_name = "CPUUtilization"
|
||||||
|
namespace = "AWS/EC2"
|
||||||
|
period = "120"
|
||||||
|
extended_statistic = "p88.0"
|
||||||
|
threshold = "80"
|
||||||
|
alarm_description = "This metric monitors ec2 cpu utilization"
|
||||||
|
evaluate_low_sample_count_percentiles = "evaluate"
|
||||||
|
insufficient_data_actions = []
|
||||||
|
dimensions {
|
||||||
|
InstanceId = "i-abc123"
|
||||||
|
}
|
||||||
|
}`, rInt)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testAccAWSCloudWatchMetricAlarmConfigTreatEvaluateLowSampleCountPercentilesUpdated(rInt int) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
resource "aws_cloudwatch_metric_alarm" "foobar" {
|
||||||
|
alarm_name = "terraform-test-foobar%d"
|
||||||
|
comparison_operator = "GreaterThanOrEqualToThreshold"
|
||||||
|
evaluation_periods = "2"
|
||||||
|
metric_name = "CPUUtilization"
|
||||||
|
namespace = "AWS/EC2"
|
||||||
|
period = "120"
|
||||||
|
extended_statistic = "p88.0"
|
||||||
|
threshold = "80"
|
||||||
|
alarm_description = "This metric monitors ec2 cpu utilization"
|
||||||
|
evaluate_low_sample_count_percentiles = "ignore"
|
||||||
|
insufficient_data_actions = []
|
||||||
|
dimensions {
|
||||||
|
InstanceId = "i-abc123"
|
||||||
|
}
|
||||||
|
}`, rInt)
|
||||||
|
}
|
||||||
|
|
||||||
func testAccAWSCloudWatchMetricAlarmConfigExtendedStatistic(rInt int) string {
|
func testAccAWSCloudWatchMetricAlarmConfigExtendedStatistic(rInt int) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "aws_cloudwatch_metric_alarm" "foobar" {
|
resource "aws_cloudwatch_metric_alarm" "foobar" {
|
||||||
|
|
|
@ -85,6 +85,12 @@ The following arguments are supported:
|
||||||
* `unit` - (Optional) The unit for the alarm's associated metric.
|
* `unit` - (Optional) The unit for the alarm's associated metric.
|
||||||
* `extended_statistic` - (Optional) The percentile statistic for the metric associated with the alarm. Specify a value between p0.0 and p100.
|
* `extended_statistic` - (Optional) The percentile statistic for the metric associated with the alarm. Specify a value between p0.0 and p100.
|
||||||
* `treat_missing_data` - (Optional) Sets how this alarm is to handle missing data points. The following values are supported: `missing`, `ignore`, `breaching` and `notBreaching`. Defaults to `missing`.
|
* `treat_missing_data` - (Optional) Sets how this alarm is to handle missing data points. The following values are supported: `missing`, `ignore`, `breaching` and `notBreaching`. Defaults to `missing`.
|
||||||
|
* `evaluate_low_sample_count_percentiles` - (Optional) Used only for alarms
|
||||||
|
based on percentiles. If you specify `ignore`, the alarm state will not
|
||||||
|
change during periods with too few data points to be statistically significant.
|
||||||
|
If you specify `evaluate` or omit this parameter, the alarm will always be
|
||||||
|
evaluated and possibly change state no matter how many data points are available.
|
||||||
|
The following values are supported: `ignore`, and `evaluate`.
|
||||||
|
|
||||||
## Attributes Reference
|
## Attributes Reference
|
||||||
|
|
||||||
|
@ -99,4 +105,4 @@ Cloud Metric Alarms can be imported using the `alarm_name`, e.g.
|
||||||
|
|
||||||
```
|
```
|
||||||
$ terraform import aws_cloudwatch_metric_alarm.test alarm-12345
|
$ terraform import aws_cloudwatch_metric_alarm.test alarm-12345
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in New Issue