This repository has been archived by the owner on Jul 29, 2020. It is now read-only.
forked from fortinetdev/terraform-provider-fortios
/
resource_system_setting_dns.go
109 lines (86 loc) · 2.35 KB
/
resource_system_setting_dns.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
package fortios
import (
"fmt"
"log"
forticlient "github.com/fortinetdev/forti-sdk-go/fortios/sdkcore"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
func resourceSystemSettingDNS() *schema.Resource {
return &schema.Resource{
Create: resourceSystemSettingDNSCreateUpdate,
Read: resourceSystemSettingDNSRead,
Update: resourceSystemSettingDNSCreateUpdate,
Delete: resourceSystemSettingDNSDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"primary": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"secondary": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"dns_over_tls": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
},
}
}
func resourceSystemSettingDNSCreateUpdate(d *schema.ResourceData, m interface{}) error {
mkey := d.Id()
c := m.(*FortiClient).Client
if c == nil {
return fmt.Errorf("FortiOS connection did not initialize successfully!")
}
c.Retries = 1
//Get Params from d
primary := d.Get("primary").(string)
secondary := d.Get("secondary").(string)
dns_over_tls := d.Get("dns_over_tls").(string)
//Build input data by sdk
i := &forticlient.JSONSystemSettingDNS{
Primary: primary,
Secondary: secondary,
DNSOverTLS: dns_over_tls,
}
//Call process by sdk
_, err := c.UpdateSystemSettingDNS(i, mkey)
if err != nil {
return fmt.Errorf("Error updating System Setting DNS: %s", err)
}
d.SetId("fortios-sys-dns")
return resourceSystemSettingDNSRead(d, m)
}
func resourceSystemSettingDNSDelete(d *schema.ResourceData, m interface{}) error {
// no API for this
return nil
}
func resourceSystemSettingDNSRead(d *schema.ResourceData, m interface{}) error {
mkey := d.Id()
c := m.(*FortiClient).Client
if c == nil {
return fmt.Errorf("FortiOS connection did not initialize successfully!")
}
c.Retries = 1
//Call process by sdk
o, err := c.ReadSystemSettingDNS(mkey)
if err != nil {
return fmt.Errorf("Error reading System Setting DNS: %s", err)
}
if o == nil {
log.Printf("[WARN] resource (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
}
d.Set("primary", o.Primary)
d.Set("secondary", o.Secondary)
d.Set("dns_over_tls", o.DNSOverTLS)
return nil
}