-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new data source `azurerm_eventhub_namespace_authorization… (#5489)
Fixes #3577
- Loading branch information
1 parent
fd6db94
commit 77ebbc4
Showing
4 changed files
with
232 additions
and
1 deletion.
There are no files selected for viewing
118 changes: 118 additions & 0 deletions
118
azurerm/internal/services/eventhub/data_source_eventhub_namespace_authorization_rule.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,118 @@ | ||
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 dataSourceEventHubNamespaceAuthorizationRule() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceEventHubNamespaceAuthorizationRuleRead, | ||
|
||
Timeouts: &schema.ResourceTimeout{ | ||
Read: schema.DefaultTimeout(5 * time.Minute), | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: azure.ValidateEventHubAuthorizationRuleName(), | ||
}, | ||
|
||
"namespace_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: azure.ValidateEventHubNamespaceName(), | ||
}, | ||
|
||
"resource_group_name": azure.SchemaResourceGroupNameForDataSource(), | ||
|
||
"listen": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
|
||
"send": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
|
||
"manage": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
|
||
"primary_key": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Sensitive: true, | ||
}, | ||
|
||
"primary_connection_string": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Sensitive: true, | ||
}, | ||
|
||
"secondary_key": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Sensitive: true, | ||
}, | ||
|
||
"secondary_connection_string": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Sensitive: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceEventHubNamespaceAuthorizationRuleRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*clients.Client).Eventhub.NamespacesClient | ||
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) | ||
defer cancel() | ||
|
||
name := d.Get("name").(string) | ||
resourceGroup := d.Get("resource_group_name").(string) | ||
namespaceName := d.Get("namespace_name").(string) | ||
|
||
resp, err := client.GetAuthorizationRule(ctx, resourceGroup, namespaceName, name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
return fmt.Errorf("Error: Azure EventHub Authorization Rule %q (Resource Group %q / Namespace Name %q) was not found", name, resourceGroup, namespaceName) | ||
} | ||
return fmt.Errorf("Error making Read request on Azure EventHub Authorization Rule %s: %+v", name, err) | ||
} | ||
|
||
d.Set("name", name) | ||
d.Set("namespace_name", namespaceName) | ||
d.Set("resource_group_name", resourceGroup) | ||
|
||
if props := resp.AuthorizationRuleProperties; props != nil { | ||
listen, send, manage := azure.FlattenEventHubAuthorizationRuleRights(props.Rights) | ||
d.Set("manage", manage) | ||
d.Set("listen", listen) | ||
d.Set("send", send) | ||
} | ||
|
||
keysResp, err := client.ListKeys(ctx, resourceGroup, namespaceName, name) | ||
if err != nil { | ||
return fmt.Errorf("Error making Read request on Azure EventHub Authorization Rule List Keys %s: %+v", name, err) | ||
} | ||
|
||
d.Set("primary_key", keysResp.PrimaryKey) | ||
d.Set("secondary_key", keysResp.SecondaryKey) | ||
d.Set("primary_connection_string", keysResp.PrimaryConnectionString) | ||
d.Set("secondary_connection_string", keysResp.SecondaryConnectionString) | ||
|
||
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
57 changes: 57 additions & 0 deletions
57
...nternal/services/eventhub/tests/data_source_eventhub_namespace_authorization_rule_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,57 @@ | ||
package tests | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" | ||
) | ||
|
||
func TestAccDataSourceAzureRMEventHubNamespaceAuthorizationRule_basic(t *testing.T) { | ||
data := acceptance.BuildTestData(t, "data.eventhub_namespace_authorization_rule", "test") | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { acceptance.PreCheck(t) }, | ||
Providers: acceptance.SupportedProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceEventHubNamespaceAuthorizationRule_basic(data, true, true, true), | ||
Check: resource.ComposeTestCheckFunc(), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceEventHubNamespaceAuthorizationRule_basic(data acceptance.TestData, listen, send, manage bool) string { | ||
return fmt.Sprintf(` | ||
resource "azurerm_resource_group" "test" { | ||
name = "acctestRG-eventhub-%[1]d" | ||
location = "%[2]s" | ||
} | ||
resource "azurerm_eventhub_namespace" "test" { | ||
name = "acctest-EHN-%[1]d" | ||
location = "${azurerm_resource_group.test.location}" | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
sku = "Standard" | ||
} | ||
resource "azurerm_eventhub_namespace_authorization_rule" "test" { | ||
name = "acctest-EHN-AR%[1]d" | ||
namespace_name = "${azurerm_eventhub_namespace.test.name}" | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
listen = %[3]t | ||
send = %[4]t | ||
manage = %[5]t | ||
} | ||
data "azurerm_eventhub_namespace_authorization_rule" "test" { | ||
name = "${azurerm_eventhub_namespace_authorization_rule.test.name}" | ||
namespace_name = "${azurerm_eventhub_namespace.test.name}" | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
} | ||
`, data.RandomInteger, data.Locations.Primary, listen, send, manage) | ||
} |
55 changes: 55 additions & 0 deletions
55
website/docs/d/eventhub_namespace_authorization_rule.html.markdown
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,55 @@ | ||
--- | ||
subcategory: "Messaging" | ||
layout: "azurerm" | ||
page_title: "Azure Resource Manager: azurerm_eventhub_namespace_authorization_rule" | ||
description: |- | ||
Gets information about an Authorization Rule for an Event Hub Namespace. | ||
--- | ||
|
||
# Data Source: azurerm_eventhub_namespace_authorization_rule | ||
|
||
Use this data source to access information about an Authorization Rule for an Event Hub Namespace. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "azurerm_eventhub_namespace_authorization_rule" "example" { | ||
name = "navi" | ||
resource_group_name = "example-resources" | ||
} | ||
output "eventhub_authorization_rule_id" { | ||
value = "${data.azurem_eventhub_namespace_authorization_rule.example.id}" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - (Required) The name of the EventHub Authorization Rule resource. | ||
|
||
* `resource_group_name` - (Required) The name of the resource group in which the EventHub Namespace exists. | ||
|
||
## Attributes Reference | ||
|
||
The following attributes are exported: | ||
|
||
* `id` - The EventHub ID. | ||
|
||
* `namespace_name` - The name of the EventHub Namespace. | ||
|
||
* `listen` - Does this Authorization Rule have permissions to Listen to the Event Hub? | ||
|
||
* `send` - Does this Authorization Rule have permissions to Send to the Event Hub? | ||
|
||
* `manage` - Does this Authorization Rule have permissions to Manage to the Event Hub? | ||
|
||
* `primary_key` - The Primary Key for the Event Hubs authorization Rule. | ||
|
||
* `primary_connection_string` - The Primary Connection String for the Event Hubs authorization Rule. | ||
|
||
* `secondary_key` - The Secondary Key for the Event Hubs authorization Rule. | ||
|
||
* `secondary_connection_string` - The Secondary Connection String for the Event Hubs authorization Rule. | ||
|