forked from openshift/terraform-provider-azurerm
/
data_source_monitor_log_profile.go
91 lines (81 loc) · 2.18 KB
/
data_source_monitor_log_profile.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
package azurerm
import (
"fmt"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
func dataSourceArmMonitorLogProfile() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmLogProfileRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"storage_account_id": {
Type: schema.TypeString,
Computed: true,
},
"servicebus_rule_id": {
Type: schema.TypeString,
Computed: true,
},
"locations": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"categories": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"retention_policy": {
Type: schema.TypeList,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Computed: true,
},
"days": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
},
}
}
func dataSourceArmLogProfileRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).monitorLogProfilesClient
ctx := meta.(*ArmClient).StopContext
name := d.Get("name").(string)
resp, err := client.Get(ctx, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Error: Log Profile %q was not found", name)
}
return fmt.Errorf("Error reading Log Profile: %+v", err)
}
d.SetId(*resp.ID)
if props := resp.LogProfileProperties; props != nil {
d.Set("storage_account_id", props.StorageAccountID)
d.Set("servicebus_rule_id", props.ServiceBusRuleID)
d.Set("categories", props.Categories)
if err := d.Set("locations", flattenAzureRmLogProfileLocations(props.Locations)); err != nil {
return fmt.Errorf("Error setting `locations`: %+v", err)
}
if err := d.Set("retention_policy", flattenAzureRmLogProfileRetentionPolicy(props.RetentionPolicy)); err != nil {
return fmt.Errorf("Error setting `retention_policy`: %+v", err)
}
}
return nil
}