This repository has been archived by the owner on Jun 9, 2023. It is now read-only.
forked from oracle/terraform-provider-oci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
core_console_history_content_data_source.go
112 lines (91 loc) · 2.52 KB
/
core_console_history_content_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
package provider
import (
"context"
"fmt"
"github.com/hashicorp/terraform/helper/schema"
oci_core "github.com/oracle/oci-go-sdk/core"
)
func CoreConsoleHistoryContentDataSource() *schema.Resource {
return &schema.Resource{
Read: readSingularCoreConsoleHistoryContent,
Schema: map[string]*schema.Schema{
"console_history_id": {
Type: schema.TypeString,
Required: true,
},
"length": {
Type: schema.TypeInt,
Optional: true,
// GetConsoleHistoryContent returns an error with length < 10240, though this is not documented in the API doc.
ValidateFunc: func(i interface{}, k string) (s []string, es []error) {
v, ok := i.(int)
if !ok {
es = append(es, fmt.Errorf("expected type of %s to be int", k))
return
}
if v < 10240 {
es = append(es, fmt.Errorf("expected %s to be less than %d, got %d", k, 10240, v))
return
}
return
},
},
"offset": {
Type: schema.TypeInt,
Optional: true,
},
// Computed
"data": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
func readSingularCoreConsoleHistoryContent(d *schema.ResourceData, m interface{}) error {
sync := &CoreConsoleHistoryContentDataSourceCrud{}
sync.D = d
sync.Client = m.(*OracleClients).computeClient
return ReadResource(sync)
}
type CoreConsoleHistoryContentDataSourceCrud struct {
D *schema.ResourceData
Client *oci_core.ComputeClient
Res *oci_core.GetConsoleHistoryContentResponse
}
func (s *CoreConsoleHistoryContentDataSourceCrud) VoidState() {
s.D.SetId("")
}
func (s *CoreConsoleHistoryContentDataSourceCrud) Get() error {
request := oci_core.GetConsoleHistoryContentRequest{}
if consoleHistoryId, ok := s.D.GetOkExists("console_history_id"); ok {
tmp := consoleHistoryId.(string)
request.InstanceConsoleHistoryId = &tmp
}
if length, ok := s.D.GetOkExists("length"); ok {
tmp := length.(int)
request.Length = &tmp
}
if offset, ok := s.D.GetOkExists("offset"); ok {
tmp := offset.(int)
request.Offset = &tmp
}
request.RequestMetadata.RetryPolicy = getRetryPolicy(false, "core")
response, err := s.Client.GetConsoleHistoryContent(context.Background(), request)
if err != nil {
return err
}
s.Res = &response
return nil
}
func (s *CoreConsoleHistoryContentDataSourceCrud) SetData() error {
if s.Res == nil {
return nil
}
s.D.SetId(GenerateDataSourceID())
if s.Res.Value != nil {
s.D.Set("data", *s.Res.Value)
}
return nil
}