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
/
dns_steering_policy_data_source.go
112 lines (84 loc) · 2.51 KB
/
dns_steering_policy_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"
"github.com/hashicorp/terraform/helper/schema"
oci_dns "github.com/oracle/oci-go-sdk/dns"
)
func DnsSteeringPolicyDataSource() *schema.Resource {
fieldMap := make(map[string]*schema.Schema)
fieldMap["steering_policy_id"] = &schema.Schema{
Type: schema.TypeString,
Required: true,
}
return GetSingularDataSourceItemSchema(DnsSteeringPolicyResource(), fieldMap, readSingularDnsSteeringPolicy)
}
func readSingularDnsSteeringPolicy(d *schema.ResourceData, m interface{}) error {
sync := &DnsSteeringPolicyDataSourceCrud{}
sync.D = d
sync.Client = m.(*OracleClients).dnsClient
return ReadResource(sync)
}
type DnsSteeringPolicyDataSourceCrud struct {
D *schema.ResourceData
Client *oci_dns.DnsClient
Res *oci_dns.GetSteeringPolicyResponse
}
func (s *DnsSteeringPolicyDataSourceCrud) VoidState() {
s.D.SetId("")
}
func (s *DnsSteeringPolicyDataSourceCrud) Get() error {
request := oci_dns.GetSteeringPolicyRequest{}
if steeringPolicyId, ok := s.D.GetOkExists("steering_policy_id"); ok {
tmp := steeringPolicyId.(string)
request.SteeringPolicyId = &tmp
}
request.RequestMetadata.RetryPolicy = getRetryPolicy(false, "dns")
response, err := s.Client.GetSteeringPolicy(context.Background(), request)
if err != nil {
return err
}
s.Res = &response
return nil
}
func (s *DnsSteeringPolicyDataSourceCrud) SetData() error {
if s.Res == nil {
return nil
}
s.D.SetId(*s.Res.Id)
answers := []interface{}{}
for _, item := range s.Res.Answers {
answers = append(answers, SteeringPolicyAnswerToMap(item))
}
s.D.Set("answers", answers)
if s.Res.CompartmentId != nil {
s.D.Set("compartment_id", *s.Res.CompartmentId)
}
if s.Res.DefinedTags != nil {
s.D.Set("defined_tags", definedTagsToMap(s.Res.DefinedTags))
}
if s.Res.DisplayName != nil {
s.D.Set("display_name", *s.Res.DisplayName)
}
s.D.Set("freeform_tags", s.Res.FreeformTags)
if s.Res.HealthCheckMonitorId != nil {
s.D.Set("health_check_monitor_id", *s.Res.HealthCheckMonitorId)
}
rules := []interface{}{}
for _, item := range s.Res.Rules {
rules = append(rules, SteeringPolicyRuleToMap(item))
}
s.D.Set("rules", rules)
if s.Res.Self != nil {
s.D.Set("self", *s.Res.Self)
}
s.D.Set("state", s.Res.LifecycleState)
s.D.Set("template", s.Res.Template)
if s.Res.TimeCreated != nil {
s.D.Set("time_created", s.Res.TimeCreated.String())
}
if s.Res.Ttl != nil {
s.D.Set("ttl", *s.Res.Ttl)
}
return nil
}