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/aws_dms_event_subscription: Mark source_ids as Optional #35541

Merged
merged 3 commits into from
Jan 29, 2024
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
3 changes: 3 additions & 0 deletions .changelog/35541.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_dms_event_subscription: Mark `source_ids` as Optional. This fixes a regression introduced in [v5.31.0](https://github.com/hashicorp/terraform-provider-aws/blob/main/CHANGELOG.md#5310-december-15-2023)
```
7 changes: 5 additions & 2 deletions internal/service/dms/event_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func ResourceEventSubscription() *schema.Resource {
"source_ids": {
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Required: true,
Optional: true,
ForceNew: true,
},
"source_type": {
Expand Down Expand Up @@ -103,12 +103,15 @@ func resourceEventSubscriptionCreate(ctx context.Context, d *schema.ResourceData
Enabled: aws.Bool(d.Get("enabled").(bool)),
EventCategories: flex.ExpandStringSet(d.Get("event_categories").(*schema.Set)),
SnsTopicArn: aws.String(d.Get("sns_topic_arn").(string)),
SourceIds: flex.ExpandStringSet(d.Get("source_ids").(*schema.Set)),
SourceType: aws.String(d.Get("source_type").(string)),
SubscriptionName: aws.String(name),
Tags: getTagsIn(ctx),
}

if v, ok := d.GetOk("source_ids"); ok && v.(*schema.Set).Len() > 0 {
input.SourceIds = flex.ExpandStringSet(v.(*schema.Set))
}

_, err := conn.CreateEventSubscriptionWithContext(ctx, input)

if err != nil {
Expand Down
15 changes: 8 additions & 7 deletions internal/service/dms/event_subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ func TestAccDMSEventSubscription_basic(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccEventSubscriptionConfig_enabled(rName, true),
Check: resource.ComposeTestCheckFunc(
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckEventSubscriptionExists(ctx, resourceName, &eventSubscription),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "source_type", "replication-instance"),
resource.TestCheckResourceAttr(resourceName, "event_categories.#", "2"),
resource.TestCheckTypeSetElemAttr(resourceName, "event_categories.*", "creation"),
resource.TestCheckTypeSetElemAttr(resourceName, "event_categories.*", "failure"),
resource.TestCheckResourceAttr(resourceName, "source_ids.#", "1"),
resource.TestCheckResourceAttrPair(resourceName, "sns_topic_arn", snsTopicResourceName, "arn"),
resource.TestCheckResourceAttr(resourceName, "source_ids.#", "0"),
resource.TestCheckResourceAttr(resourceName, "source_type", "replication-instance"),
),
},
{
Expand Down Expand Up @@ -133,12 +133,13 @@ func TestAccDMSEventSubscription_eventCategories(t *testing.T) {
CheckDestroy: testAccCheckEventSubscriptionDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccEventSubscriptionConfig_categories2(rName, "creation", "failure"),
Config: testAccEventSubscriptionConfig_eventCategories(rName, "creation", "failure"),
Check: resource.ComposeTestCheckFunc(
testAccCheckEventSubscriptionExists(ctx, resourceName, &eventSubscription),
resource.TestCheckResourceAttr(resourceName, "event_categories.#", "2"),
resource.TestCheckTypeSetElemAttr(resourceName, "event_categories.*", "creation"),
resource.TestCheckTypeSetElemAttr(resourceName, "event_categories.*", "failure"),
resource.TestCheckResourceAttr(resourceName, "source_ids.#", "1"),
),
},
{
Expand All @@ -147,12 +148,13 @@ func TestAccDMSEventSubscription_eventCategories(t *testing.T) {
ImportStateVerify: true,
},
{
Config: testAccEventSubscriptionConfig_categories2(rName, "configuration change", "deletion"),
Config: testAccEventSubscriptionConfig_eventCategories(rName, "configuration change", "deletion"),
Check: resource.ComposeTestCheckFunc(
testAccCheckEventSubscriptionExists(ctx, resourceName, &eventSubscription),
resource.TestCheckResourceAttr(resourceName, "event_categories.#", "2"),
resource.TestCheckTypeSetElemAttr(resourceName, "event_categories.*", "configuration change"),
resource.TestCheckTypeSetElemAttr(resourceName, "event_categories.*", "deletion"),
resource.TestCheckResourceAttr(resourceName, "source_ids.#", "1"),
),
},
},
Expand Down Expand Up @@ -282,13 +284,12 @@ resource "aws_dms_event_subscription" "test" {
enabled = %[2]t
event_categories = ["creation", "failure"]
source_type = "replication-instance"
source_ids = [aws_dms_replication_instance.test.replication_instance_id]
sns_topic_arn = aws_sns_topic.test.arn
}
`, rName, enabled))
}

func testAccEventSubscriptionConfig_categories2(rName string, eventCategory1 string, eventCategory2 string) string {
func testAccEventSubscriptionConfig_eventCategories(rName string, eventCategory1, eventCategory2 string) string {
return acctest.ConfigCompose(testAccEventSubscriptionConfig_base(rName), fmt.Sprintf(`
resource "aws_dms_event_subscription" "test" {
name = %[1]q
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/dms_event_subscription.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ This resource supports the following arguments:
* `name` - (Required) Name of event subscription.
* `enabled` - (Optional, Default: true) Whether the event subscription should be enabled.
* `event_categories` - (Optional) List of event categories to listen for, see `DescribeEventCategories` for a canonical list.
* `source_type` - (Required) Type of source for events. Valid values: `replication-instance` or `replication-task`
* `source_ids` - (Required) Ids of sources to listen to.
* `sns_topic_arn` - (Required) SNS topic arn to send events on.
* `source_ids` - (Optional) Ids of sources to listen to. If you don't specify a value, notifications are provided for all sources.
* `source_type` - (Required) Type of source for events. Valid values: `replication-instance` or `replication-task`
* `tags` - (Optional) Map of resource tags to assign to the resource. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level.

## Attribute Reference
Expand Down
Loading