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

New data source: azurerm_eventhub_cluster #11763

Merged
merged 9 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
66 changes: 66 additions & 0 deletions azurerm/internal/services/eventhub/eventhub_cluster_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
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/services/eventhub/parse"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func dataSourceEventHubCluster() *schema.Resource {
return &schema.Resource{
Read: dataSourceEventHubClusterRead,

Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(5 * time.Minute),
},

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},

"resource_group_name": azure.SchemaResourceGroupName(),

"sku_name": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func dataSourceEventHubClusterRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Eventhub.ClusterClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)

subscriptionId := meta.(*clients.Client).Account.SubscriptionId
id := parse.NewClusterID(subscriptionId, resourceGroup, name)
resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("%s was not found", id)
}
return fmt.Errorf("making Read request on Azure EventHub Cluster %q (Resource Group %q): %+v", name, resourceGroup, err)
}
d.SetId(id.ID())

d.Set("name", resp.Name)
d.Set("resource_group_name", resourceGroup)
d.Set("sku_name", flattenEventHubClusterSkuName(resp.Sku))
if location := resp.Location; location != nil {
d.Set("location", azure.NormalizeLocation(*location))
}

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package eventhub_test

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/check"
)

type EventHubClusterDataSource struct {
}

func TestAccEventHubClusterDataSource_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_eventhub", "test")
r := EventHubClusterDataSource{}

data.DataSourceTest(t, []resource.TestStep{
{
Config: r.basic(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("sku_name").HasValue("Dedicated_1"),
),
},
})
}

func (EventHubClusterDataSource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-eventhub-%[1]d"
location = "%[2]s"
}

resource "azurerm_eventhub_cluster" "test" {
name = "acctesteventhubclusTER-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
sku_name = "Dedicated_1"
}

data "azurerm_eventhub_cluster" "test" {
name = azurerm_eventhub.test.name
resource_group_name = azurerm_resource_group.test.name
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}
1 change: 1 addition & 0 deletions azurerm/internal/services/eventhub/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func (r Registration) WebsiteCategories() []string {
func (r Registration) SupportedDataSources() map[string]*schema.Resource {
return map[string]*schema.Resource{
"azurerm_eventhub": dataSourceEventHub(),
"azurerm_eventhub_cluster": dataSourceEventHubCluster(),
"azurerm_eventhub_authorization_rule": EventHubAuthorizationRuleDataSource(),
"azurerm_eventhub_consumer_group": EventHubConsumerGroupDataSource(),
"azurerm_eventhub_namespace": EventHubNamespaceDataSource(),
Expand Down
46 changes: 46 additions & 0 deletions website/docs/d/eventhub_cluster.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
subcategory: "Messaging"
layout: "azurerm"
page_title: "Azure Resource Manager: Data Source: azurerm_eventhub_cluster"
description: |-
Gets information about an existing EventHub Cluster.
---

# Data Source: azurerm_eventhub_cluster

Use this data source to access information about an existing EventHub.

## Example Usage

```hcl
data "azurerm_eventhub_cluster" "example" {
name = "search-eventhub"
resource_group_name = "search-service"
}

output "eventhub_id" {
value = data.azurerm_eventhub_cluster.example.id
}
```

## Arguments Reference

The following arguments are supported:

* `name` - (Required) The name of this EventHub Cluster.

* `resource_group_name` - (Required) The name of the Resource Group where the EventHub Cluster exists.

## Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:

* `id` - The ID of the EventHub Cluster.

* `sku_name` - SKU name of the EventHub Cluster.

## Timeouts

The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions:

* `read` - (Defaults to 5 minutes) Used when retrieving the EventHub Cluster.