diff --git a/.changelog/35541.txt b/.changelog/35541.txt new file mode 100644 index 00000000000..33dc8a8b4ad --- /dev/null +++ b/.changelog/35541.txt @@ -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) +``` \ No newline at end of file diff --git a/internal/service/dms/event_subscription.go b/internal/service/dms/event_subscription.go index e9226398b07..f745a0de5a5 100644 --- a/internal/service/dms/event_subscription.go +++ b/internal/service/dms/event_subscription.go @@ -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": { @@ -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 { diff --git a/internal/service/dms/event_subscription_test.go b/internal/service/dms/event_subscription_test.go index 45f3d0c15c6..8463287ba3a 100644 --- a/internal/service/dms/event_subscription_test.go +++ b/internal/service/dms/event_subscription_test.go @@ -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"), ), }, { @@ -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"), ), }, { @@ -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"), ), }, }, @@ -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 diff --git a/website/docs/r/dms_event_subscription.html.markdown b/website/docs/r/dms_event_subscription.html.markdown index 3d53fe93610..d9fffa2110d 100644 --- a/website/docs/r/dms_event_subscription.html.markdown +++ b/website/docs/r/dms_event_subscription.html.markdown @@ -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