-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
data_source_eventhub_namespace.go
132 lines (105 loc) · 3.47 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
120
121
122
123
124
125
126
127
128
129
130
131
132
package azurerm
import (
"fmt"
"log"
"time"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
func dataSourceEventHubNamespace() *schema.Resource {
return &schema.Resource{
Read: dataSourceEventHubNamespaceRead,
Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(5 * time.Minute),
},
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),
"location": azure.SchemaLocationForDataSource(),
"sku": {
Type: schema.TypeString,
Computed: true,
},
"capacity": {
Type: schema.TypeInt,
Computed: true,
},
"auto_inflate_enabled": {
Type: schema.TypeBool,
Computed: true,
},
"kafka_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": tags.SchemaDataSource(),
},
}
}
func dataSourceEventHubNamespaceRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).Eventhub.NamespacesClient
ctx, cancel := timeouts.ForRead(meta.(*ArmClient).StopContext, d)
defer cancel()
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", azure.NormalizeLocation(*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("kafka_enabled", props.KafkaEnabled)
d.Set("maximum_throughput_units", int(*props.MaximumThroughputUnits))
}
return tags.FlattenAndSet(d, resp.Tags)
}