diff --git a/azurerm/internal/services/eventhub/eventhub_consumer_group_data_source.go b/azurerm/internal/services/eventhub/eventhub_consumer_group_data_source.go index c79004c7375a..60bf2c12ca4f 100644 --- a/azurerm/internal/services/eventhub/eventhub_consumer_group_data_source.go +++ b/azurerm/internal/services/eventhub/eventhub_consumer_group_data_source.go @@ -5,6 +5,7 @@ import ( "time" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" @@ -21,9 +22,12 @@ func dataSourceEventHubConsumerGroup() *schema.Resource { Schema: map[string]*schema.Schema{ "name": { - Type: schema.TypeString, - Required: true, - ValidateFunc: azure.ValidateEventHubConsumerName(), + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.Any( + azure.ValidateEventHubConsumerName(), + validation.StringInSlice([]string{"$Default"}, false), + ), }, "namespace_name": { diff --git a/azurerm/internal/services/eventhub/tests/eventhub_consumer_group_data_source_test.go b/azurerm/internal/services/eventhub/tests/eventhub_consumer_group_data_source_test.go index 3802cf8da05d..edd20c779fb4 100644 --- a/azurerm/internal/services/eventhub/tests/eventhub_consumer_group_data_source_test.go +++ b/azurerm/internal/services/eventhub/tests/eventhub_consumer_group_data_source_test.go @@ -27,6 +27,25 @@ func TestAccDataSourceAzureRMEventHubConsumerGroup_complete(t *testing.T) { }) } +func TestAccDataSourceAzureRMEventHubConsumerGroupDefault_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_eventhub_consumer_group", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubConsumerGroupDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMEventHubConsumerGroupDefault_complete(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubConsumerGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "user_metadata", "some-meta-data"), + ), + }, + }, + }) +} + func testAccDataSourceAzureRMEventHubConsumerGroup_complete(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { @@ -69,3 +88,38 @@ data "azurerm_eventhub_consumer_group" "test" { } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } + +func testAccDataSourceAzureRMEventHubConsumerGroupDefault_complete(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_eventhub_namespace" "test" { + name = "acctesteventhubnamespace-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Standard" +} + +resource "azurerm_eventhub" "test" { + name = "acctesteventhub-%d" + namespace_name = azurerm_eventhub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name + partition_count = 2 + message_retention = 7 +} + +data "azurerm_eventhub_consumer_group" "test" { + name = "$Default" + namespace_name = azurerm_eventhub_namespace.test.name + eventhub_name = azurerm_eventhub.test.name + resource_group_name = azurerm_resource_group.test.name +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +}