forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New data source:
azurerm_eventhub_cluster
(hashicorp#11763)
Co-authored-by: Tom Harvey <[email protected]>
- Loading branch information
1 parent
ee4003f
commit 08c31a0
Showing
4 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
azurerm/internal/services/eventhub/eventhub_cluster_data_source.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,68 @@ | ||
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(), | ||
|
||
"location": azure.SchemaLocationForDataSource(), | ||
|
||
"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 | ||
} |
52 changes: 52 additions & 0 deletions
52
azurerm/internal/services/eventhub/eventhub_cluster_data_source_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,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_cluster", "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_cluster.test.name | ||
resource_group_name = azurerm_resource_group.test.name | ||
} | ||
`, data.RandomInteger, data.Locations.Primary, 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,48 @@ | ||
--- | ||
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. | ||
|
||
* `location` - Location 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. |