Skip to content

Commit

Permalink
resource/aws_cloudwatch_metric_alarm: Accept EC2 automate reboot ARN
Browse files Browse the repository at this point in the history
Previously:

```
--- FAIL: TestAccAWSCloudWatchMetricAlarm_AlarmActions_EC2Automate (9.08s)
    testing.go:538: Step 0 error: Error planning: 2 errors occurred:
        	* aws_cloudwatch_metric_alarm.test: "alarm_actions.0" doesn't look like a valid ARN ("^arn:[\\w-]+:([a-zA-Z0-9\\-])+:([a-z]{2}-(gov-)?[a-z]+-\\d{1})?:(\\d{12})?:(.*)$"): "arn:aws:automate:us-west-2:ec2:reboot"
        	* aws_cloudwatch_metric_alarm.test: "alarm_actions.0" does not match EC2 automation ARN ("^arn:[\\w-]+:automate:[\\w-]+:ec2:(recover|stop|terminate)$"): "arn:aws:automate:us-west-2:ec2:reboot"
```

```
--- PASS: TestAccAWSCloudWatchMetricAlarm_AlarmActions_EC2Automate (194.97s)
```
  • Loading branch information
bflad committed Nov 8, 2018
1 parent 368dfc3 commit 965300d
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 965300d

Please sign in to comment.