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

azurerm_eventhub_consumer_group - allow the name property to be set to $Default #8388

Merged
merged 7 commits into from
Sep 13, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions azurerm/helpers/azure/eventhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ func ValidateEventHubConsumerName() schema.SchemaValidateFunc {
)
}

func ValidateEventHubConsumerDataSourceName() schema.SchemaValidateFunc {
return validation.StringMatch(
regexp.MustCompile("^[a-zA-Z0-9]([-._$$a-zA-Z0-9]{0,48}[a-zA-Z0-9])?$"),
"The consumer group name can contain only letters, numbers, periods (.), hyphens (-),and underscores (_), up to 50 characters, and it must begin and end with a letter or number.",
)
}

func ValidateEventHubAuthorizationRuleName() schema.SchemaValidateFunc {
return validation.StringMatch(
regexp.MustCompile("^[a-zA-Z0-9]([-._a-zA-Z0-9]{0,48}[a-zA-Z0-9])?$"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func dataSourceEventHubConsumerGroup() *schema.Resource {
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: azure.ValidateEventHubConsumerName(),
ValidateFunc: azure.ValidateEventHubConsumerDataSourceName(),
favoretti marked this conversation as resolved.
Show resolved Hide resolved
},

"namespace_name": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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)
}