/
database_db_home_data_source.go
97 lines (73 loc) · 2.12 KB
/
database_db_home_data_source.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
// Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
package provider
import (
"context"
"fmt"
"github.com/hashicorp/terraform/helper/schema"
oci_database "github.com/oracle/oci-go-sdk/database"
)
func DatabaseDbHomeDataSource() *schema.Resource {
fieldMap := make(map[string]*schema.Schema)
fieldMap["db_home_id"] = &schema.Schema{
Type: schema.TypeString,
Required: true,
}
return GetSingularDataSourceItemSchema(DatabaseDbHomeResource(), fieldMap, readSingularDatabaseDbHome)
}
func readSingularDatabaseDbHome(d *schema.ResourceData, m interface{}) error {
sync := &DatabaseDbHomeDataSourceCrud{}
sync.D = d
sync.Client = m.(*OracleClients).databaseClient
return ReadResource(sync)
}
type DatabaseDbHomeDataSourceCrud struct {
D *schema.ResourceData
Client *oci_database.DatabaseClient
Res *oci_database.GetDbHomeResponse
}
func (s *DatabaseDbHomeDataSourceCrud) VoidState() {
s.D.SetId("")
}
func (s *DatabaseDbHomeDataSourceCrud) Get() error {
request := oci_database.GetDbHomeRequest{}
if dbHomeId, ok := s.D.GetOkExists("db_home_id"); ok {
tmp := dbHomeId.(string)
if len(tmp) == 0 {
return fmt.Errorf("db_home_id must contain a valid ocid")
}
request.DbHomeId = &tmp
}
request.RequestMetadata.RetryPolicy = getRetryPolicy(false, "database")
response, err := s.Client.GetDbHome(context.Background(), request)
if err != nil {
return err
}
s.Res = &response
return nil
}
func (s *DatabaseDbHomeDataSourceCrud) SetData() error {
if s.Res == nil {
return nil
}
s.D.SetId(*s.Res.Id)
if s.Res.CompartmentId != nil {
s.D.Set("compartment_id", *s.Res.CompartmentId)
}
if s.Res.DbSystemId != nil {
s.D.Set("db_system_id", *s.Res.DbSystemId)
}
if s.Res.DbVersion != nil {
s.D.Set("db_version", *s.Res.DbVersion)
}
if s.Res.DisplayName != nil {
s.D.Set("display_name", *s.Res.DisplayName)
}
if s.Res.LastPatchHistoryEntryId != nil {
s.D.Set("last_patch_history_entry_id", *s.Res.LastPatchHistoryEntryId)
}
s.D.Set("state", s.Res.LifecycleState)
if s.Res.TimeCreated != nil {
s.D.Set("time_created", s.Res.TimeCreated.String())
}
return nil
}