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

r/db event subscription: set source type when updating categories #2833

Merged
merged 1 commit into from
Jan 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions aws/resource_aws_db_event_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ func resourceAwsDbEventSubscriptionUpdate(d *schema.ResourceData, meta interface
for i, eventCategory := range eventCategoriesSet.List() {
req.EventCategories[i] = aws.String(eventCategory.(string))
}
req.SourceType = aws.String(d.Get("source_type").(string))
requestUpdate = true
}

Expand Down
54 changes: 54 additions & 0 deletions aws/resource_aws_db_event_subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,41 @@ func TestAccAWSDBEventSubscription_withSourceIds(t *testing.T) {
})
}

func TestAccAWSDBEventSubscription_categoryUpdate(t *testing.T) {
var v rds.EventSubscription
rInt := acctest.RandInt()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSDBEventSubscriptionDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSDBEventSubscriptionConfig(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBEventSubscriptionExists("aws_db_event_subscription.bar", &v),
resource.TestCheckResourceAttr(
"aws_db_event_subscription.bar", "enabled", "true"),
resource.TestCheckResourceAttr(
"aws_db_event_subscription.bar", "source_type", "db-instance"),
resource.TestCheckResourceAttr(
"aws_db_event_subscription.bar", "name", fmt.Sprintf("tf-acc-test-rds-event-subs-%d", rInt)),
),
},
{
Config: testAccAWSDBEventSubscriptionConfigUpdateCategories(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBEventSubscriptionExists("aws_db_event_subscription.bar", &v),
resource.TestCheckResourceAttr(
"aws_db_event_subscription.bar", "enabled", "true"),
resource.TestCheckResourceAttr(
"aws_db_event_subscription.bar", "source_type", "db-instance"),
),
},
},
})
}

func testAccCheckAWSDBEventSubscriptionExists(n string, v *rds.EventSubscription) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -263,3 +298,22 @@ func testAccAWSDBEventSubscriptionConfigUpdateSourceIds(rInt int) string {
}
}`, rInt, rInt, rInt, rInt)
}

func testAccAWSDBEventSubscriptionConfigUpdateCategories(rInt int) string {
return fmt.Sprintf(`
resource "aws_sns_topic" "aws_sns_topic" {
name = "tf-acc-test-rds-event-subs-sns-topic-%d"
}

resource "aws_db_event_subscription" "bar" {
name = "tf-acc-test-rds-event-subs-%d"
sns_topic = "${aws_sns_topic.aws_sns_topic.arn}"
source_type = "db-instance"
event_categories = [
"availability",
]
tags {
Name = "name"
}
}`, rInt, rInt)
}