Skip to content

Commit

Permalink
Merge pull request #6405 from terraform-providers/b-aws_cloudwatch_me…
Browse files Browse the repository at this point in the history
…tric_alarm-ec2-automate-reboot

resource/aws_cloudwatch_metric_alarm: Accept EC2 automate reboot ARN
  • Loading branch information
bflad authored Nov 9, 2018
2 parents 368dfc3 + 965300d commit b987318
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
23 changes: 22 additions & 1 deletion aws/resource_aws_cloudwatch_metric_alarm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestAccAWSCloudWatchMetricAlarm_AlarmActions_EC2Automate(t *testing.T) {
CheckDestroy: testAccCheckAWSCloudWatchMetricAlarmDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSCloudWatchMetricAlarmConfigAlarmActionsEC2Automate(rName, "recover"),
Config: testAccAWSCloudWatchMetricAlarmConfigAlarmActionsEC2Automate(rName, "reboot"),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudWatchMetricAlarmExists(resourceName, &alarm),
resource.TestCheckResourceAttr(resourceName, "alarm_actions.#", "1"),
Expand All @@ -65,6 +65,27 @@ func TestAccAWSCloudWatchMetricAlarm_AlarmActions_EC2Automate(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccAWSCloudWatchMetricAlarmConfigAlarmActionsEC2Automate(rName, "recover"),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudWatchMetricAlarmExists(resourceName, &alarm),
resource.TestCheckResourceAttr(resourceName, "alarm_actions.#", "1"),
),
},
{
Config: testAccAWSCloudWatchMetricAlarmConfigAlarmActionsEC2Automate(rName, "stop"),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudWatchMetricAlarmExists(resourceName, &alarm),
resource.TestCheckResourceAttr(resourceName, "alarm_actions.#", "1"),
),
},
{
Config: testAccAWSCloudWatchMetricAlarmConfigAlarmActionsEC2Automate(rName, "terminate"),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudWatchMetricAlarmExists(resourceName, &alarm),
resource.TestCheckResourceAttr(resourceName, "alarm_actions.#", "1"),
),
},
},
})
}
Expand Down
2 changes: 1 addition & 1 deletion aws/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ func validateEC2AutomateARN(v interface{}, k string) (ws []string, errors []erro
value := v.(string)

// https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_PutMetricAlarm.html
pattern := `^arn:[\w-]+:automate:[\w-]+:ec2:(recover|stop|terminate)$`
pattern := `^arn:[\w-]+:automate:[\w-]+:ec2:(reboot|recover|stop|terminate)$`
if !regexp.MustCompile(pattern).MatchString(value) {
errors = append(errors, fmt.Errorf(
"%q does not match EC2 automation ARN (%q): %q",
Expand Down
1 change: 1 addition & 0 deletions aws/validators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ func TestValidateArn(t *testing.T) {

func TestValidateEC2AutomateARN(t *testing.T) {
validNames := []string{
"arn:aws:automate:us-east-1:ec2:reboot",
"arn:aws:automate:us-east-1:ec2:recover",
"arn:aws:automate:us-east-1:ec2:stop",
"arn:aws:automate:us-east-1:ec2:terminate",
Expand Down

0 comments on commit b987318

Please sign in to comment.