forked from oracle/terraform-provider-oci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_source_obmcs_database_db_home.go
84 lines (76 loc) · 1.82 KB
/
data_source_obmcs_database_db_home.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
// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
package main
import (
"github.com/MustWin/baremetal-sdk-go"
"github.com/hashicorp/terraform/helper/schema"
"github.com/oracle/terraform-provider-baremetal/client"
"github.com/oracle/terraform-provider-baremetal/crud"
)
func DBHomeDatasource() *schema.Resource {
return &schema.Resource{
Read: readDBHome,
Schema: map[string]*schema.Schema{
"compartment_id": {
Type: schema.TypeString,
Computed: true,
},
"db_system_id": {
Type: schema.TypeString,
Computed: true,
},
"db_version": {
Type: schema.TypeString,
Computed: true,
},
"display_name": {
Type: schema.TypeString,
Computed: true,
},
"id": {
Type: schema.TypeString,
Computed: true,
},
"db_home_id": {
Type: schema.TypeString,
Required: true,
},
"state": {
Type: schema.TypeString,
Computed: true,
},
"time_created": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
func readDBHome(d *schema.ResourceData, m interface{}) (e error) {
client := m.(client.BareMetalClient)
sync := &DBHomeDatasourceCrud{}
sync.D = d
sync.Client = client
return crud.ReadResource(sync)
}
type DBHomeDatasourceCrud struct {
crud.BaseCrud
Res *baremetal.DBHome
}
func (s *DBHomeDatasourceCrud) Get() (e error) {
id := s.D.Get("db_home_id").(string)
s.Res, e = s.Client.GetDBHome(id)
return
}
func (s *DBHomeDatasourceCrud) SetData() {
if s.Res != nil {
s.D.SetId(s.Res.ID)
s.D.Set("compartment_id", s.Res.CompartmentID)
s.D.Set("db_system_id", s.Res.DBSystemID)
s.D.Set("db_version", s.Res.DBVersion)
s.D.Set("display_name", s.Res.DisplayName)
s.D.Set("id", s.Res.ID)
s.D.Set("state", s.Res.State)
s.D.Set("time_created", s.Res.TimeCreated.String())
}
return
}