forked from huaweicloud/terraform-provider-huaweicloud
/
data_source_huaweicloud_cts_tracker_v1.go
116 lines (100 loc) · 2.96 KB
/
data_source_huaweicloud_cts_tracker_v1.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
package huaweicloud
import (
"fmt"
"log"
"github.com/hashicorp/terraform/helper/schema"
"github.com/huaweicloud/golangsdk/openstack/cts/v1/tracker"
)
func dataSourceCTSTrackerV1() *schema.Resource {
return &schema.Resource{
Read: dataSourceCTSTrackerV1Read,
Schema: map[string]*schema.Schema{
"region": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"status": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"bucket_name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"file_prefix_name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"tracker_name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"is_support_smn": {
Type: schema.TypeBool,
Computed: true,
},
"topic_id": {
Type: schema.TypeString,
Computed: true,
},
"operations": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
"is_send_all_key_operation": {
Type: schema.TypeBool,
Computed: true,
},
"need_notify_user_list": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
},
}
}
func dataSourceCTSTrackerV1Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
trackerClient, err := config.ctsV1Client(GetRegion(d, config))
listOpts := tracker.ListOpts{
TrackerName: d.Get("tracker_name").(string),
BucketName: d.Get("bucket_name").(string),
FilePrefixName: d.Get("file_prefix_name").(string),
Status: d.Get("status").(string),
}
refinedTrackers, err := tracker.List(trackerClient, listOpts)
if err != nil {
return fmt.Errorf("Unable to retrieve cts tracker: %s", err)
}
if len(refinedTrackers) < 1 {
return fmt.Errorf("Your query returned no results. " +
"Please change your search criteria and try again.")
}
if len(refinedTrackers) > 1 {
return fmt.Errorf("Your query returned more than one result." +
" Please try a more specific search criteria")
}
trackers := refinedTrackers[0]
log.Printf("[INFO] Retrieved cts tracker %s using given filter", trackers.TrackerName)
d.SetId(trackers.TrackerName)
d.Set("tracker_name", trackers.TrackerName)
d.Set("bucket_name", trackers.BucketName)
d.Set("file_prefix_name", trackers.FilePrefixName)
d.Set("status", trackers.Status)
d.Set("is_support_smn", trackers.SimpleMessageNotification.IsSupportSMN)
d.Set("topic_id", trackers.SimpleMessageNotification.TopicID)
d.Set("is_send_all_key_operation", trackers.SimpleMessageNotification.IsSendAllKeyOperation)
d.Set("operations", trackers.SimpleMessageNotification.Operations)
d.Set("need_notify_user_list", trackers.SimpleMessageNotification.NeedNotifyUserList)
d.Set("region", GetRegion(d, config))
return nil
}