/
resource_aviatrix_splunk_logging.go
118 lines (104 loc) · 3.24 KB
/
resource_aviatrix_splunk_logging.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
package aviatrix
import (
"fmt"
"strconv"
"strings"
"github.com/AviatrixSystems/terraform-provider-aviatrix/v3/goaviatrix"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func resourceAviatrixSplunkLogging() *schema.Resource {
return &schema.Resource{
Create: resourceAviatrixSplunkLoggingCreate,
Read: resourceAviatrixSplunkLoggingRead,
Delete: resourceAviatrixSplunkLoggingDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"server": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "Server IP.",
},
"port": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Description: "Port number.",
},
"custom_output_config_file": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
return strings.TrimSpace(old) == strings.TrimSpace(new)
},
Description: "Configuration file. Use the filebase64 function to read from a file.",
},
"custom_input_config": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
return strings.TrimSpace(old) == strings.TrimSpace(new)
},
Description: "Custom configuration.",
},
"excluded_gateways": {
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
Description: "List of excluded gateways.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "Enabled or not.",
},
},
}
}
func resourceAviatrixSplunkLoggingCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*goaviatrix.Client)
_, err := client.GetSplunkLoggingStatus()
if err != goaviatrix.ErrNotFound {
return fmt.Errorf("the splunk_logging is already enabled, please import to manage with Terraform")
} else {
return fmt.Errorf("the support for splunk logging is deprecated")
}
}
func resourceAviatrixSplunkLoggingRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*goaviatrix.Client)
if d.Id() != "splunk_logging" {
return fmt.Errorf("invalid ID, expected ID \"splunk_logging\", instead got %s", d.Id())
}
splunkLoggingStatus, err := client.GetSplunkLoggingStatus()
if err == goaviatrix.ErrNotFound {
d.SetId("")
return nil
}
if err != nil {
return fmt.Errorf("could not get splunk logging status: %v", err)
}
d.Set("server", splunkLoggingStatus.Server)
port, _ := strconv.Atoi(splunkLoggingStatus.Port)
d.Set("port", port)
d.Set("custom_input_config", splunkLoggingStatus.CustomConfig)
d.Set("status", splunkLoggingStatus.Status)
if len(splunkLoggingStatus.ExcludedGateways) != 0 {
d.Set("excluded_gateways", splunkLoggingStatus.ExcludedGateways)
}
d.SetId("splunk_logging")
return nil
}
func resourceAviatrixSplunkLoggingDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*goaviatrix.Client)
if err := client.DisableSplunkLogging(); err != nil {
return fmt.Errorf("could not disable splunk logging: %v", err)
}
return nil
}