forked from oracle/terraform-provider-oci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_source_obmcs_database_db_system_shape.go
118 lines (102 loc) · 2.73 KB
/
data_source_obmcs_database_db_system_shape.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
// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
package main
import (
"time"
"github.com/hashicorp/terraform/helper/schema"
"github.com/oracle/bmcs-go-sdk"
"github.com/oracle/terraform-provider-oci/options"
"github.com/oracle/terraform-provider-oci/crud"
)
func DBSystemShapeDatasource() *schema.Resource {
return &schema.Resource{
Read: readDBSystemShapes,
Schema: map[string]*schema.Schema{
"db_system_shapes": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"available_core_count": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"shape": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"availability_domain": {
Type: schema.TypeString,
Required: true,
},
"compartment_id": {
Type: schema.TypeString,
Required: true,
},
"limit": {
Type: schema.TypeInt,
Optional: true,
},
"page": {
Type: schema.TypeString,
Optional: true,
},
},
}
}
func readDBSystemShapes(d *schema.ResourceData, m interface{}) (e error) {
client := m.(*OracleClients)
reader := &DBSystemShapeDatasourceCrud{}
reader.D = d
reader.Client = client.client
return crud.ReadResource(reader)
}
type DBSystemShapeDatasourceCrud struct {
crud.BaseCrud
Res *baremetal.ListDBSystemShapes
}
func (s *DBSystemShapeDatasourceCrud) Get() (e error) {
availabilityDomain := s.D.Get("availability_domain").(string)
compartmentID := s.D.Get("compartment_id").(string)
opts := &baremetal.ListOptions{}
options.SetPageOptions(s.D, &opts.PageListOptions)
options.SetLimitOptions(s.D, &opts.LimitListOptions)
s.Res = &baremetal.ListDBSystemShapes{}
for {
var list *baremetal.ListDBSystemShapes
if list, e = s.Client.ListDBSystemShapes(
availabilityDomain, compartmentID, opts,
); e != nil {
break
}
s.Res.DBSystemShapes = append(s.Res.DBSystemShapes, list.DBSystemShapes...)
if hasNextPage := options.SetNextPageOption(list.NextPage, &opts.PageListOptions); !hasNextPage {
break
}
}
return
}
func (s *DBSystemShapeDatasourceCrud) SetData() {
if s.Res != nil {
// Important, if you don't have an ID, make one up for your datasource
// or things will end in tears
s.D.SetId(time.Now().UTC().String())
resources := []map[string]interface{}{}
for _, v := range s.Res.DBSystemShapes {
res := map[string]interface{}{
"available_core_count": v.AvailableCoreCount,
"name": v.Name,
"shape": v.Shape,
}
resources = append(resources, res)
}
s.D.Set("db_system_shapes", resources)
}
return
}