-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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_notification_hub_namespace
``` $ 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
1 parent
04d2a79
commit d1c720b
Showing
5 changed files
with
206 additions
and
1 deletion.
There are no files selected for viewing
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,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 | ||
} |
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,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) | ||
} |
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
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 @@ | ||
--- | ||
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.` |