Skip to content

Commit

Permalink
New Data Source: azurerm_notification_hub_namespace
Browse files Browse the repository at this point in the history
```
$ acctests azurerm TestAccDataSourceAzureRMNotificationHubNamespace_free
=== RUN   TestAccDataSourceAzureRMNotificationHubNamespace_free
--- PASS: TestAccDataSourceAzureRMNotificationHubNamespace_free (130.03s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	130.081s
```
  • Loading branch information
tombuildsstuff committed Jul 17, 2018
1 parent 04d2a79 commit d1c720b
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 1 deletion.
110 changes: 110 additions & 0 deletions azurerm/data_source_notification_hub_namespace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package azurerm

import (
"fmt"

"github.com/Azure/azure-sdk-for-go/services/notificationhubs/mgmt/2017-04-01/notificationhubs"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func dataSourceNotificationHubNamespace() *schema.Resource {
return &schema.Resource{
Read: resourceArmDataSourceNotificationHubNamespaceRead,

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

"resource_group_name": resourceGroupNameForDataSourceSchema(),

"location": locationForDataSourceSchema(),

"sku": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},
},
},
},

"enabled": {
Type: schema.TypeBool,
Computed: true,
},

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

// NOTE: skipping tags as there's a bug in the API where the Keys for Tags are returned in lower-case
// Azure Rest API Specs issue: https://github.com/Azure/azure-sdk-for-go/issues/2239
//"tags": tagsForDataSourceSchema(),

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

func resourceArmDataSourceNotificationHubNamespaceRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).notificationNamespacesClient
ctx := meta.(*ArmClient).StopContext

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

resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Notification Hub Namespace %q (Resource Group %q) was not found", name, resourceGroup)
}

return fmt.Errorf("Error making Read request on Notification Hub Namespace %q (Resource Group %q): %+v", name, resourceGroup, err)
}

d.SetId(*resp.ID)

d.Set("name", resp.Name)
d.Set("resource_group_name", resourceGroup)
if location := resp.Location; location != nil {
d.Set("location", azureRMNormalizeLocation(*location))
}

sku := flattenNotificationHubDataSourceNamespacesSku(resp.Sku)
if err := d.Set("sku", sku); err != nil {
return fmt.Errorf("Error setting `sku`: %+v", err)
}

if props := resp.NamespaceProperties; props != nil {
d.Set("enabled", props.Enabled)
d.Set("namespace_type", props.NamespaceType)
d.Set("servicebus_endpoint", props.ServiceBusEndpoint)
}

return nil
}

func flattenNotificationHubDataSourceNamespacesSku(input *notificationhubs.Sku) []interface{} {
outputs := make([]interface{}, 0)
if input == nil {
return outputs
}

output := map[string]interface{}{
"name": string(input.Name),
}
outputs = append(outputs, output)
return outputs
}
43 changes: 43 additions & 0 deletions azurerm/data_source_notification_hub_namespace_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package azurerm

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-website/ext/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccDataSourceAzureRMNotificationHubNamespace_free(t *testing.T) {
dataSourceName := "data.azurerm_notification_hub_namespace.test"
rInt := acctest.RandInt()
location := testLocation()
config := testAccDataSourceAzureRMNotificationHubNamespaceFree(rInt, location)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMNotificationHubNamespaceDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "namespace_type", "NotificationHub"),
resource.TestCheckResourceAttr(dataSourceName, "sku.0.name", "Free"),
),
},
},
})
}

func testAccDataSourceAzureRMNotificationHubNamespaceFree(rInt int, location string) string {
resource := testAzureRMNotificationHubNamespace_free(rInt, location)
return fmt.Sprintf(`
%s
data "azurerm_notification_hub_namespace" "test" {
name = "${azurerm_notification_hub_namespace.test.name}"
resource_group_name = "${azurerm_notification_hub_namespace.test.resource_group_name}"
}
`, resource)
}
1 change: 1 addition & 0 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_managed_disk": dataSourceArmManagedDisk(),
"azurerm_network_interface": dataSourceArmNetworkInterface(),
"azurerm_network_security_group": dataSourceArmNetworkSecurityGroup(),
"azurerm_notification_hub_namespace": dataSourceNotificationHubNamespace(),
"azurerm_platform_image": dataSourceArmPlatformImage(),
"azurerm_public_ip": dataSourceArmPublicIP(),
"azurerm_public_ips": dataSourceArmPublicIPs(),
Expand Down
5 changes: 4 additions & 1 deletion website/azurerm.erb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
<a href="/docs/providers/azurerm/d/cosmosdb_account.html">azurerm_cosmosdb_account</a>
</li>


<li<%= sidebar_current("docs-azurerm-datasource-dns-zone") %>>
<a href="/docs/providers/azurerm/d/dns_zone.html">azurerm_dns_zone</a>
</li>
Expand Down Expand Up @@ -108,6 +107,10 @@
<a href="/docs/providers/azurerm/d/network_security_group.html">azurerm_network_security_group</a>
</li>

<li<%= sidebar_current("docs-azurerm-datasource-notification-hub-namespace") %>>
<a href="/docs/providers/azurerm/d/notification_hub_namespace.html">azurerm_notification_hub_namespace</a>
</li>

<li<%= sidebar_current("docs-azurerm-datasource-platform-image") %>>
<a href="/docs/providers/azurerm/d/platform_image.html">azurerm_platform_image</a>
</li>
Expand Down
48 changes: 48 additions & 0 deletions website/docs/d/notification_hub_namespace.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
layout: "azurerm"
page_title: "Azure Resource Manager: azurerm_notification_hub_namespace"
sidebar_current: "docs-azurerm-datasource-notification-hub-namespace"
description: |-
Gets information about the specified Notification Hub Namespace.
---

# Data Source: azurerm_notification_hub_namespace

Gets information about the specified Notification Hub Namespace.

## Example Usage

```hcl
data "azurerm_notification_hub_namespace" "test" {
name = "${azurerm_network_security_group.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
}
output "location" {
value = "${data.azurerm_notification_hub_namespace.test.servicebus_endpoint}"
}
```

## Argument Reference

* `name` - (Required) Specifies the Name of the Notification Hub Namespace.

* `resource_group_name` - (Required) Specifies the Name of the Resource Group within which the Notification Hub exists.

## Attributes Reference

* `id` - The ID of the Notification Hub Namespace.

* `location` - The Azure Region in which this Notification Hub Namespace exists.

* `namespace_type` - The Type of Namespace, such as `Messaging` or `NotificationHub`.

* `sku` - A `sku` block as defined below.

* `enabled` - Is this Notification Hub Namespace enabled?

---

A `sku` block exports the following:

* `name` - (Required) The name of the SKU to use for this Notification Hub Namespace. Possible values are `Free`, `Basic` or `Standard.`

0 comments on commit d1c720b

Please sign in to comment.