From 70b5e91ce3ebc5f4d2668a29b63148cca3faf677 Mon Sep 17 00:00:00 2001 From: kondo takeshi Date: Mon, 22 Jul 2019 00:42:08 +0900 Subject: [PATCH] Add test for cloudwatch event target import --- ...resource_aws_cloudwatch_event_target_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/aws/resource_aws_cloudwatch_event_target_test.go b/aws/resource_aws_cloudwatch_event_target_test.go index 37c55e7b533..ca22b2bf203 100644 --- a/aws/resource_aws_cloudwatch_event_target_test.go +++ b/aws/resource_aws_cloudwatch_event_target_test.go @@ -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, + }, }, }) } @@ -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" {