forked from huaweicloud/terraform-provider-huaweicloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_source_huaweicloud_dms_maintainwindow_v1.go
87 lines (77 loc) · 1.85 KB
/
data_source_huaweicloud_dms_maintainwindow_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
package huaweicloud
import (
"fmt"
"log"
"strconv"
"github.com/hashicorp/terraform/helper/schema"
"github.com/huaweicloud/golangsdk/openstack/dms/v1/maintainwindows"
)
func dataSourceDmsMaintainWindowV1() *schema.Resource {
return &schema.Resource{
Read: dataSourceDmsMaintainWindowV1Read,
Schema: map[string]*schema.Schema{
"seq": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
"begin": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"end": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"default": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
},
}
}
func dataSourceDmsMaintainWindowV1Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
dmsV1Client, err := config.dmsV1Client(GetRegion(d, config))
if err != nil {
return fmt.Errorf("Error creating HuaweiCloud kms key client: %s", err)
}
v, err := maintainwindows.Get(dmsV1Client).Extract()
if err != nil {
return err
}
maintainWindows := v.MaintainWindows
var filteredMVs []maintainwindows.MaintainWindow
for _, mv := range maintainWindows {
seq := d.Get("seq").(int)
if seq != 0 && mv.ID != seq {
continue
}
begin := d.Get("begin").(string)
if begin != "" && mv.Begin != begin {
continue
}
end := d.Get("end").(string)
if end != "" && mv.End != end {
continue
}
df := d.Get("default").(bool)
if mv.Default != df {
continue
}
filteredMVs = append(filteredMVs, mv)
}
if len(filteredMVs) < 1 {
return fmt.Errorf("Your query returned no results. Please change your filters and try again.")
}
mw := filteredMVs[0]
d.SetId(strconv.Itoa(mw.ID))
d.Set("begin", mw.Begin)
d.Set("end", mw.End)
d.Set("default", mw.Default)
log.Printf("[DEBUG] Dms MaintainWindow : %+v", mw)
return nil
}