forked from fortinetdev/terraform-provider-fortios
/
resource_log_syslog_setting.go
140 lines (118 loc) · 3.02 KB
/
resource_log_syslog_setting.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package fortios
import (
"fmt"
"log"
"github.com/fortinetdev/forti-sdk-go/fortios/sdkcore"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func resourceLogSyslogSetting() *schema.Resource {
return &schema.Resource{
Create: resourceLogSyslogSettingCreateUpdate,
Read: resourceLogSyslogSettingRead,
Update: resourceLogSyslogSettingCreateUpdate,
Delete: resourceLogSyslogSettingDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"status": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
"server": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"mode": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"port": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"facility": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"source_ip": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"format": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
},
}
}
func resourceLogSyslogSettingCreateUpdate(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
status := d.Get("status").(string)
server := d.Get("server").(string)
mode := d.Get("mode").(string)
port := d.Get("port").(string)
facility := d.Get("facility").(string)
sourceIP := d.Get("source_ip").(string)
format := d.Get("format").(string)
//Build input data by sdk
i := &forticlient.JSONLogSyslogSetting{
Status: status,
Server: server,
Mode: mode,
Port: port,
Facility: facility,
SourceIP: sourceIP,
Format: format,
}
//Call process by sdk
_, err := c.UpdateLogSyslogSetting(i, mkey)
if err != nil {
return fmt.Errorf("Error updating Log Syslog Setting: %s", err)
}
d.SetId(server)
return resourceLogSyslogSettingRead(d, m)
}
func resourceLogSyslogSettingDelete(d *schema.ResourceData, m interface{}) error {
// no API for this
return nil
}
func resourceLogSyslogSettingRead(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.ReadLogSyslogSetting(mkey)
if err != nil {
return fmt.Errorf("Error reading Log Syslog Setting: %s", err)
}
if o == nil {
log.Printf("[WARN] resource (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
}
//Refresh property
d.Set("status", o.Status)
d.Set("server", o.Server)
d.Set("mode", o.Mode)
d.Set("port", o.Port)
d.Set("facility", o.Facility)
d.Set("source_ip", o.SourceIP)
d.Set("format", o.Format)
return nil
}