Skip to content

Commit

Permalink
Add test for cloudwatch event target import
Browse files Browse the repository at this point in the history
  • Loading branch information
chaspy committed Jul 21, 2019
1 parent 64c2fed commit 70b5e91
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions aws/resource_aws_cloudwatch_event_target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ func TestAccAWSCloudWatchEventTarget_basic(t *testing.T) {
regexp.MustCompile(fmt.Sprintf(":%s$", snsTopicName2))),
),
},
{
ResourceName: "aws_cloudwatch_event_target.moobar",
ImportState: true,
ImportStateIdFunc: testAccAWSCloudWatchEventTargetImportStateIdFunc("aws_cloudwatch_event_target.moobar"),
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -332,6 +338,17 @@ func testAccCheckAWSCloudWatchEventTargetDestroy(s *terraform.State) error {
return nil
}

func testAccAWSCloudWatchEventTargetImportStateIdFunc(resourceName string) resource.ImportStateIdFunc {
return func(s *terraform.State) (string, error) {
rs, ok := s.RootModule().Resources[resourceName]
if !ok {
return "", fmt.Errorf("Not found: %s", resourceName)
}

return fmt.Sprintf("%s/%s", rs.Primary.Attributes["rule"], rs.Primary.Attributes["target_id"]), nil
}
}

func testAccAWSCloudWatchEventTargetConfig(ruleName, snsTopicName, targetID string) string {
return fmt.Sprintf(`
resource "aws_cloudwatch_event_rule" "foo" {
Expand Down

0 comments on commit 70b5e91

Please sign in to comment.