-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5518 from brunhil/eventhub_consumer_group_datasource
New Data Source: 'azurerm_eventhub_consumer_group'
- Loading branch information
Showing
6 changed files
with
199 additions
and
1 deletion.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
azurerm/internal/services/eventhub/data_source_eventhub_consumer_group.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package eventhub | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"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" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func dataSourceEventHubConsumerGroup() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceArmEventHubConsumerGroupRead, | ||
|
||
Timeouts: &schema.ResourceTimeout{ | ||
Read: schema.DefaultTimeout(5 * time.Minute), | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: azure.ValidateEventHubConsumerName(), | ||
}, | ||
|
||
"namespace_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: azure.ValidateEventHubNamespaceName(), | ||
}, | ||
|
||
"eventhub_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: azure.ValidateEventHubName(), | ||
}, | ||
|
||
"resource_group_name": azure.SchemaResourceGroupNameForDataSource(), | ||
|
||
"location": azure.SchemaLocationForDataSource(), | ||
|
||
"user_metadata": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceArmEventHubConsumerGroupRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*clients.Client).Eventhub.ConsumerGroupClient | ||
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) | ||
defer cancel() | ||
|
||
name := d.Get("name").(string) | ||
resourceGroup := d.Get("resource_group_name").(string) | ||
eventHubName := d.Get("eventhub_name").(string) | ||
namespaceName := d.Get("namespace_name").(string) | ||
|
||
resp, err := client.Get(ctx, resourceGroup, namespaceName, eventHubName, name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
return fmt.Errorf("Error: EventHub Consumer Group %q (Resource Group %q) was not found", name, resourceGroup) | ||
} | ||
return fmt.Errorf("Error: EventHub Consumer Group %s: %+v", name, err) | ||
} | ||
|
||
d.SetId(*resp.ID) | ||
|
||
d.Set("name", name) | ||
d.Set("eventhub_name", eventHubName) | ||
d.Set("namespace_name", namespaceName) | ||
d.Set("resource_group_name", resourceGroup) | ||
|
||
if resp.ConsumerGroupProperties != nil { | ||
d.Set("user_metadata", resp.ConsumerGroupProperties.UserMetadata) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
azurerm/internal/services/eventhub/tests/data_source_eventhub_consumer_group_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package tests | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" | ||
) | ||
|
||
func TestAccDataSourceAzureRMEventHubConsumerGroup_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: testAccDataSourceAzureRMEventHubConsumerGroup_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(` | ||
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 | ||
} | ||
resource "azurerm_eventhub_consumer_group" "test" { | ||
name = "acctesteventhubcg-%d" | ||
namespace_name = "${azurerm_eventhub_namespace.test.name}" | ||
eventhub_name = "${azurerm_eventhub.test.name}" | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
user_metadata = "some-meta-data" | ||
} | ||
data "azurerm_eventhub_consumer_group" "test" { | ||
name = "${azurerm_eventhub_consumer_group.test.name}" | ||
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, data.RandomInteger) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
subcategory: "Messaging" | ||
layout: "azurerm" | ||
page_title: "Azure Resource Manager: azurerm_eventhub_consumer_group" | ||
description: |- | ||
Gets information about an Event Hubs Consumer Group within an Event Hub. | ||
--- | ||
|
||
# Data Source: azurerm_eventhub_consumer_group | ||
|
||
Use this data source to access information about an existing Event Hubs Consumer Group within an Event Hub. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "azurerm_eventhub_consumer_group" "test" { | ||
name = "${azurerm_eventhub_consumer_group.test.name}" | ||
namespace_name = "${azurerm_eventhub_namespace.test.name}" | ||
eventhub_name = "${azurerm_eventhub.test.name}" | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `name` - Specifies the name of the EventHub Consumer Group resource. | ||
|
||
* `namespace_name` - Specifies the name of the grandparent EventHub Namespace. | ||
|
||
* `eventhub_name` - Specifies the name of the EventHub. | ||
|
||
* `resource_group_name` - The name of the resource group in which the EventHub Consumer Group's grandparent Namespace exists. | ||
|
||
## Attributes Reference | ||
|
||
The following attributes are exported: | ||
|
||
* `id` - The EventHub Consumer Group ID. | ||
|
||
* `user_metadata` - Specifies the user metadata. |