/
core_letter_of_authority_data_source.go
116 lines (94 loc) · 2.55 KB
/
core_letter_of_authority_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
113
114
115
116
// Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
package provider
import (
"context"
"github.com/hashicorp/terraform/helper/schema"
oci_core "github.com/oracle/oci-go-sdk/core"
)
func CoreLetterOfAuthorityDataSource() *schema.Resource {
return &schema.Resource{
Read: readSingularCoreLetterOfAuthority,
Schema: map[string]*schema.Schema{
"cross_connect_id": {
Type: schema.TypeString,
Required: true,
},
// Computed
"authorized_entity_name": {
Type: schema.TypeString,
Computed: true,
},
"circuit_type": {
Type: schema.TypeString,
Computed: true,
},
"facility_location": {
Type: schema.TypeString,
Computed: true,
},
"port_name": {
Type: schema.TypeString,
Computed: true,
},
"time_expires": {
Type: schema.TypeString,
Computed: true,
},
"time_issued": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
func readSingularCoreLetterOfAuthority(d *schema.ResourceData, m interface{}) error {
sync := &CoreLetterOfAuthorityDataSourceCrud{}
sync.D = d
sync.Client = m.(*OracleClients).virtualNetworkClient
return ReadResource(sync)
}
type CoreLetterOfAuthorityDataSourceCrud struct {
D *schema.ResourceData
Client *oci_core.VirtualNetworkClient
Res *oci_core.GetCrossConnectLetterOfAuthorityResponse
}
func (s *CoreLetterOfAuthorityDataSourceCrud) VoidState() {
s.D.SetId("")
}
func (s *CoreLetterOfAuthorityDataSourceCrud) Get() error {
request := oci_core.GetCrossConnectLetterOfAuthorityRequest{}
if crossConnectId, ok := s.D.GetOkExists("cross_connect_id"); ok {
tmp := crossConnectId.(string)
request.CrossConnectId = &tmp
}
request.RequestMetadata.RetryPolicy = getRetryPolicy(false, "core")
response, err := s.Client.GetCrossConnectLetterOfAuthority(context.Background(), request)
if err != nil {
return err
}
s.Res = &response
return nil
}
func (s *CoreLetterOfAuthorityDataSourceCrud) SetData() error {
if s.Res == nil {
return nil
}
s.D.SetId(GenerateDataSourceID())
if s.Res.AuthorizedEntityName != nil {
s.D.Set("authorized_entity_name", *s.Res.AuthorizedEntityName)
}
s.D.Set("circuit_type", s.Res.CircuitType)
if s.Res.FacilityLocation != nil {
s.D.Set("facility_location", *s.Res.FacilityLocation)
}
if s.Res.PortName != nil {
s.D.Set("port_name", *s.Res.PortName)
}
if s.Res.TimeExpires != nil {
s.D.Set("time_expires", s.Res.TimeExpires.String())
}
if s.Res.TimeIssued != nil {
s.D.Set("time_issued", s.Res.TimeIssued.String())
}
return nil
}