forked from openshift/terraform-provider-azurerm
/
data_source_notification_hub_namespace.go
109 lines (87 loc) · 2.81 KB
/
data_source_notification_hub_namespace.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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,
},
"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
}