Skip to content

Commit

Permalink
Fixing EventHub Authorisation rules
Browse files Browse the repository at this point in the history
  • Loading branch information
tombuildsstuff committed Oct 12, 2017
1 parent d8b2e7e commit 54c3df9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 30 deletions.
13 changes: 5 additions & 8 deletions azurerm/resource_arm_eventhub_authorization_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func resourceArmEventHubAuthorizationRule() *schema.Resource {

"resource_group_name": resourceGroupNameSchema(),

"location": locationSchema(),
"location": deprecatedLocationSchema(),

"listen": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -89,7 +89,6 @@ func resourceArmEventHubAuthorizationRuleCreateUpdate(d *schema.ResourceData, me
log.Printf("[INFO] preparing arguments for AzureRM EventHub Authorization Rule creation.")

name := d.Get("name").(string)
location := d.Get("location").(string)
namespaceName := d.Get("namespace_name").(string)
eventHubName := d.Get("eventhub_name").(string)
resGroup := d.Get("resource_group_name").(string)
Expand All @@ -99,10 +98,9 @@ func resourceArmEventHubAuthorizationRuleCreateUpdate(d *schema.ResourceData, me
return err
}

parameters := eventhub.SharedAccessAuthorizationRuleCreateOrUpdateParameters{
Name: &name,
Location: &location,
SharedAccessAuthorizationRuleProperties: &eventhub.SharedAccessAuthorizationRuleProperties{
parameters := eventhub.AuthorizationRule{
Name: &name,
AuthorizationRuleProperties: &eventhub.AuthorizationRuleProperties{
Rights: rights,
},
}
Expand Down Expand Up @@ -153,7 +151,6 @@ func resourceArmEventHubAuthorizationRuleRead(d *schema.ResourceData, meta inter
}

d.Set("name", name)
d.Set("location", azureRMNormalizeLocation(*resp.Location))
d.Set("eventhub_name", eventHubName)
d.Set("namespace_name", namespaceName)
d.Set("resource_group_name", resGroup)
Expand Down Expand Up @@ -217,7 +214,7 @@ func expandEventHubAuthorizationRuleAccessRights(d *schema.ResourceData) (*[]eve
return &rights, nil
}

func flattenEventHubAuthorizationRuleAccessRights(d *schema.ResourceData, resp eventhub.SharedAccessAuthorizationRuleResource) {
func flattenEventHubAuthorizationRuleAccessRights(d *schema.ResourceData, resp eventhub.AuthorizationRule) {

var canListen = false
var canSend = false
Expand Down
26 changes: 8 additions & 18 deletions azurerm/resource_arm_eventhub_authorization_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package azurerm

import (
"fmt"
"net/http"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func TestAccAzureRMEventHubAuthorizationRule_listen(t *testing.T) {
Expand Down Expand Up @@ -101,11 +101,9 @@ func testCheckAzureRMEventHubAuthorizationRuleDestroy(s *terraform.State) error

resp, err := conn.GetAuthorizationRule(resourceGroup, namespaceName, eventHubName, name)
if err != nil {
return nil
}

if resp.StatusCode != http.StatusNotFound {
return fmt.Errorf("EventHub Authorization Rule still exists:\n%#v", resp)
if !utils.ResponseWasNotFound(resp.Response) {
return err
}
}
}

Expand All @@ -131,11 +129,11 @@ func testCheckAzureRMEventHubAuthorizationRuleExists(name string) resource.TestC
conn := testAccProvider.Meta().(*ArmClient).eventHubClient
resp, err := conn.GetAuthorizationRule(resourceGroup, namespaceName, eventHubName, name)
if err != nil {
return fmt.Errorf("Bad: Get on eventHubClient: %s", err)
}
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Bad: Event Hub Authorization Rule %q (eventhub %s, namespace %s / resource group: %s) does not exist", name, eventHubName, namespaceName, resourceGroup)
}

if resp.StatusCode == http.StatusNotFound {
return fmt.Errorf("Bad: Event Hub Authorization Rule %q (eventhub %s, namespace %s / resource group: %s) does not exist", name, eventHubName, namespaceName, resourceGroup)
return fmt.Errorf("Bad: Get on eventHubClient: %+v", err)
}

return nil
Expand All @@ -160,7 +158,6 @@ resource "azurerm_eventhub" "test" {
name = "acctesteventhub-%d"
namespace_name = "${azurerm_eventhub_namespace.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
partition_count = 2
message_retention = 7
}
Expand All @@ -170,7 +167,6 @@ resource "azurerm_eventhub_authorization_rule" "test" {
namespace_name = "${azurerm_eventhub_namespace.test.name}"
eventhub_name = "${azurerm_eventhub.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
listen = true
send = false
manage = false
Expand All @@ -196,7 +192,6 @@ resource "azurerm_eventhub" "test" {
name = "acctesteventhub-%d"
namespace_name = "${azurerm_eventhub_namespace.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
partition_count = 2
message_retention = 7
}
Expand All @@ -206,7 +201,6 @@ resource "azurerm_eventhub_authorization_rule" "test" {
namespace_name = "${azurerm_eventhub_namespace.test.name}"
eventhub_name = "${azurerm_eventhub.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
listen = false
send = true
manage = false
Expand All @@ -232,7 +226,6 @@ resource "azurerm_eventhub" "test" {
name = "acctesteventhub-%d"
namespace_name = "${azurerm_eventhub_namespace.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
partition_count = 2
message_retention = 7
}
Expand All @@ -242,7 +235,6 @@ resource "azurerm_eventhub_authorization_rule" "test" {
namespace_name = "${azurerm_eventhub_namespace.test.name}"
eventhub_name = "${azurerm_eventhub.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
listen = true
send = true
manage = false
Expand All @@ -268,7 +260,6 @@ resource "azurerm_eventhub" "test" {
name = "acctesteventhub-%d"
namespace_name = "${azurerm_eventhub_namespace.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
partition_count = 2
message_retention = 7
}
Expand All @@ -278,7 +269,6 @@ resource "azurerm_eventhub_authorization_rule" "test" {
namespace_name = "${azurerm_eventhub_namespace.test.name}"
eventhub_name = "${azurerm_eventhub.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
listen = true
send = true
manage = true
Expand Down
4 changes: 0 additions & 4 deletions website/docs/r/eventhub_authorization_rule.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ resource "azurerm_eventhub_namespace" "test" {
resource "azurerm_eventhub" "test" {
name = "acceptanceTestEventHub"
namespace_name = "${azurerm_eventhub_namespace.test.name}"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
partition_count = 2
message_retention = 2
Expand All @@ -44,7 +43,6 @@ resource "azurerm_eventhub_authorization_rule" "test" {
namespace_name = "${azurerm_eventhub_namespace.test.name}"
eventhub_name = "${azurerm_eventhub.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
listen = true
send = false
manage = false
Expand All @@ -63,8 +61,6 @@ The following arguments are supported:

* `resource_group_name` - (Required) The name of the resource group in which the EventHub Namespace exists. Changing this forces a new resource to be created.

* `location` - (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created.

~> **NOTE** At least one of the 3 permissions below needs to be set.

* `listen` - (Optional) Does this Authorization Rule have permissions to Listen to the Event Hub? Defaults to `false`.
Expand Down

2 comments on commit 54c3df9

@pixelicous
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tombuildsstuff Authorization rule should be possible to create on event hub namespace or eventhub, it is not a requirement to build rules on eventhubs only.. too bad its configured in such manner

@tombuildsstuff
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pixelicous unfortunately the name Authorization Rule is used in multiple contexts within Azure, where Authorization Rules in the context of this resource are specific to an EventHub.

It's also possible to create a Shared Access Policy (which is also known as an Authorization Rule) directly on an EventHub Namespace (as you're referring too). There's a related feature request for adding support for Shared Access Policies here which you may wish to subscribe too :)

Thanks!

Please sign in to comment.