forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_source_eventhub_namespace.go
119 lines (93 loc) · 2.95 KB
/
data_source_eventhub_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
110
111
112
113
114
115
116
117
118
119
package azurerm
import (
"fmt"
"log"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
func dataSourceEventHubNamespace() *schema.Resource {
return &schema.Resource{
Read: dataSourceEventHubNamespaceRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"resource_group_name": resourceGroupNameForDataSourceSchema(),
"location": locationForDataSourceSchema(),
"sku": {
Type: schema.TypeString,
Computed: true,
},
"capacity": {
Type: schema.TypeInt,
Computed: true,
},
"auto_inflate_enabled": {
Type: schema.TypeBool,
Computed: true,
},
"maximum_throughput_units": {
Type: schema.TypeInt,
Computed: true,
},
"default_primary_connection_string": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},
"default_secondary_connection_string": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},
"default_primary_key": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},
"default_secondary_key": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},
"tags": tagsForDataSourceSchema(),
},
}
}
func dataSourceEventHubNamespaceRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).eventHubNamespacesClient
ctx := meta.(*ArmClient).StopContext
resourceGroup := d.Get("resource_group_name").(string)
name := d.Get("name").(string)
resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Error: EventHub Namespace %q (Resource Group %q) was not found", name, resourceGroup)
}
return fmt.Errorf("Error making Read request on EventHub 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))
}
d.Set("sku", string(resp.Sku.Name))
d.Set("capacity", resp.Sku.Capacity)
keys, err := client.ListKeys(ctx, resourceGroup, name, eventHubNamespaceDefaultAuthorizationRule)
if err != nil {
log.Printf("[WARN] Unable to List default keys for EventHub Namespace %q (Resource Group %q): %+v", name, resourceGroup, err)
} else {
d.Set("default_primary_connection_string", keys.PrimaryConnectionString)
d.Set("default_secondary_connection_string", keys.SecondaryConnectionString)
d.Set("default_primary_key", keys.PrimaryKey)
d.Set("default_secondary_key", keys.SecondaryKey)
}
if props := resp.EHNamespaceProperties; props != nil {
d.Set("auto_inflate_enabled", props.IsAutoInflateEnabled)
d.Set("maximum_throughput_units", int(*props.MaximumThroughputUnits))
}
flattenAndSetTags(d, resp.Tags)
return nil
}