Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/fix removed resource error handling for aws cloudwatch event permission resource #9044

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add disappeared resource test case
  • Loading branch information
teraken0509 committed Jun 19, 2019
commit 18cbb6b91e27eadca7303f6d1bd6b7d6a75597de
42 changes: 42 additions & 0 deletions aws/resource_aws_cloudwatch_event_permission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,48 @@ func TestAccAWSCloudWatchEventPermission_Multiple(t *testing.T) {
})
}

func TestAccAWSCloudWatchEventPermission_Disappears(t *testing.T) {
resourceName := "aws_cloudwatch_event_permission.test1"
principal := "111111111111"
statementID := acctest.RandomWithPrefix(t.Name())[:64]

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckCloudWatchEventPermissionDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckAwsCloudWatchEventPermissionResourceConfigBasic(principal, statementID),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudWatchEventPermissionExists(resourceName),
testAccCheckCloudWatchEventPermissionDisappears(resourceName),
),
ExpectNonEmptyPlan: true,
},
},
})
}

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

if rs.Primary.ID == "" {
return fmt.Errorf("No resource ID is set")
}

conn := testAccProvider.Meta().(*AWSClient).cloudwatcheventsconn
input := events.RemovePermissionInput{
StatementId: aws.String(rs.Primary.ID),
}
_, err := conn.RemovePermission(&input)
return err
}
}

func testAccCheckCloudWatchEventPermissionExists(pr string) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).cloudwatcheventsconn
Expand Down