Skip to content

Commit 95e61fd

Browse files
add sumologic_installed_collector resource (#182)
* add sumologic_installed_collector resource * remove forceNew * add missing installed collector parameters * add docs for sumologic_installed_collector * Resolve lint errors * address PR comments * fix datatype for LastSeenAlive param and remove omitEmpty for Ephemeral Co-authored-by: Vishal Sahu <[email protected]>
1 parent 4be4a43 commit 95e61fd

File tree

5 files changed

+199
-1
lines changed

5 files changed

+199
-1
lines changed

sumologic/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func Provider() terraform.ResourceProvider {
6060
"sumologic_cse_match_rule": resourceSumologicCSEMatchRule(),
6161
"sumologic_cse_threshold_rule": resourceSumologicCSEThresholdRule(),
6262
"sumologic_collector": resourceSumologicCollector(),
63+
"sumologic_installed_collector": resourceSumologicInstalledCollector(),
6364
"sumologic_http_source": resourceSumologicHTTPSource(),
6465
"sumologic_gcp_source": resourceSumologicGCPSource(),
6566
"sumologic_polling_source": resourceSumologicPollingSource(),

sumologic/resource_sumologic_collector.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@ func resourceSumologicCollectorRead(d *schema.ResourceData, meta interface{}) er
8787
return fmt.Errorf("error setting fields for resource %s: %s", d.Id(), err)
8888
}
8989

90+
if collector.CollectorType == "Installable" {
91+
d.Set("host_name", collector.HostName)
92+
d.Set("ephemeral", collector.Ephemeral)
93+
d.Set("source_sync_mode", collector.SourceSyncMode)
94+
d.Set("cutoff_timestamp", collector.CutoffTimestamp)
95+
d.Set("alive", collector.Alive)
96+
d.Set("last_seen_alive", collector.LastSeenAlive)
97+
d.Set("collector_version", collector.CollectorVersion)
98+
99+
}
100+
90101
return nil
91102
}
92103

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package sumologic
2+
3+
import (
4+
"strconv"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
7+
)
8+
9+
func resourceSumologicInstalledCollector() *schema.Resource {
10+
return &schema.Resource{
11+
Read: resourceSumologicCollectorRead,
12+
Delete: resourceSumologicCollectorDelete,
13+
Update: resourceSumologicInstalledCollectorUpdate,
14+
Importer: &schema.ResourceImporter{
15+
State: schema.ImportStatePassthrough,
16+
},
17+
18+
Schema: map[string]*schema.Schema{
19+
"name": {
20+
Type: schema.TypeString,
21+
Required: true,
22+
},
23+
"description": {
24+
Type: schema.TypeString,
25+
Optional: true,
26+
},
27+
"category": {
28+
Type: schema.TypeString,
29+
Optional: true,
30+
},
31+
"cutoff_timestamp": {
32+
Type: schema.TypeInt,
33+
Optional: true,
34+
Default: 0,
35+
},
36+
"timezone": {
37+
Type: schema.TypeString,
38+
Optional: true,
39+
Default: "Etc/UTC",
40+
},
41+
"ephemeral": {
42+
Type: schema.TypeBool,
43+
Required: true,
44+
},
45+
"fields": {
46+
Type: schema.TypeMap,
47+
Elem: &schema.Schema{
48+
Type: schema.TypeString,
49+
},
50+
Optional: true,
51+
},
52+
"host_name": {
53+
Type: schema.TypeString,
54+
Optional: true,
55+
Default: "",
56+
},
57+
"alive": {
58+
Type: schema.TypeBool,
59+
Computed: true,
60+
},
61+
"last_seen_alive": {
62+
Type: schema.TypeInt,
63+
Computed: true,
64+
},
65+
"source_sync_mode": {
66+
Type: schema.TypeString,
67+
Optional: true,
68+
Default: "UI",
69+
},
70+
"target_cpu": {
71+
Type: schema.TypeInt,
72+
Optional: true,
73+
},
74+
"collector_version": {
75+
Type: schema.TypeString,
76+
Computed: true,
77+
},
78+
},
79+
}
80+
}
81+
82+
func resourceSumologicInstalledCollectorUpdate(d *schema.ResourceData, meta interface{}) error {
83+
84+
collector := resourceToInstalledCollector(d)
85+
86+
c := meta.(*Client)
87+
err := c.UpdateCollector(collector)
88+
89+
if err != nil {
90+
return err
91+
}
92+
93+
return resourceSumologicCollectorRead(d, meta)
94+
}
95+
96+
func resourceToInstalledCollector(d *schema.ResourceData) Collector {
97+
id, _ := strconv.Atoi(d.Id())
98+
99+
return Collector{
100+
ID: int64(id),
101+
CollectorType: "Installable",
102+
Name: d.Get("name").(string),
103+
Description: d.Get("description").(string),
104+
Category: d.Get("category").(string),
105+
TimeZone: d.Get("timezone").(string),
106+
HostName: d.Get("host_name").(string),
107+
Ephemeral: d.Get("ephemeral").(bool),
108+
SourceSyncMode: d.Get("source_sync_mode").(string),
109+
Targetcpu: d.Get("target_cpu").(int),
110+
Fields: d.Get("fields").(map[string]interface{}),
111+
CutoffTimestamp: d.Get("cutoff_timestamp").(int),
112+
Alive: d.Get("alive").(bool),
113+
LastSeenAlive: d.Get("last_seen_alive").(int),
114+
CollectorVersion: d.Get("collector_version").(string),
115+
}
116+
}

sumologic/sumologic_collectors.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ type Collector struct {
110110
Fields map[string]interface{} `json:"fields,omitempty"`
111111
Links []CollectorLink `json:"links,omitempty"`
112112
CollectorVersion string `json:"collectorVersion,omitempty"`
113-
LastSeenAlive int64 `json:"lastSeenAlive,omitempty"`
113+
LastSeenAlive int `json:"lastSeenAlive,omitempty"`
114114
Alive bool `json:"alive,omitempty"`
115+
HostName string `json:"hostName,omitempty"`
116+
Ephemeral bool `json:"ephemeral"`
117+
SourceSyncMode string `json:"sourceSyncMode,omitempty"`
118+
Targetcpu int `json:"targetCpu,omitempty"`
119+
CutoffTimestamp int `json:"cutoffTimestamp,omitempty"`
115120
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
layout: "sumologic"
3+
page_title: "SumoLogic: sumologic_installed_collector"
4+
description: |-
5+
Provides a Sumologic (Installed) Collector.
6+
---
7+
8+
# sumologic_collector
9+
Provides a [Sumologic (Installed) Collector][1].
10+
**NOTE**: This resource can only be imported and managed by terraform. Creation of this resource via terrform is not supported.
11+
12+
## Example Usage
13+
```hcl
14+
resource "sumologic_installed_collector" "installed_collector" {
15+
name = "test-mac"
16+
category = "macos/test"
17+
ephemeral = true
18+
fields = {
19+
key = "value"
20+
}
21+
}
22+
```
23+
24+
## Argument Reference
25+
26+
The following arguments are supported:
27+
28+
* `name` - (Required) The name of the collector. This is required, and has to be unique. Changing this will force recreation the collector.
29+
* `ephemeral` - (Required) When true, the collector will be deleted after 12 hours of inactivity. For more information, see [Setting a Collector as Ephemeral][5].
30+
* `description` - (Optional) The description of the collector.
31+
* `category` - (Optional) The default source category for any source attached to this collector. Can be overridden in the configuration of said sources.
32+
* `timezone` - (Optional) The time zone to use for this collector. The value follows the [tzdata][2] naming convention.
33+
* `fields` - (Optional) Map containing [key/value pairs][3].
34+
* `cutOffTimestamp` - (Optional) Only collect data from files with a modified date more recent than this timestamp, specified as milliseconds since epoch.
35+
* `hostName` - (Optional) Host name of the Collector. The hostname can be a maximum of 128 characters.
36+
* `sourceSyncMode` - (Optional) For installed Collectors, whether the Collector is using local source configuration management (using a JSON file), or cloud management (using the UI)
37+
* `targetCpu` - When CPU utilization exceeds this threshold, the Collector will slow down its rate of ingestion to lower its CPU utilization. Currently only Local and Remote File Sources are supported.
38+
39+
### See also
40+
* [Common Collector Properties](https://help.sumologic.com/APIs/Collector-Management-API/Collector-API-Methods-and-Examples#response-fields)
41+
* [Common Source Properties](https://github.com/terraform-providers/terraform-provider-sumologic/tree/master/website#common-source-properties)
42+
43+
## Attributes Reference
44+
The following attributes are exported:
45+
46+
* `id` - The internal ID of the collector. This can be used to attach sources to the collector.
47+
48+
## Import
49+
Collectors can be imported using the collector id, e.g.:
50+
51+
```hcl
52+
terraform import sumologic_collector.test 1234567890
53+
```
54+
55+
Collectors can also be imported using the collector name, which is unique per Sumo Logic account, e.g.:
56+
57+
```hcl
58+
terraform import sumologic_collector.test my_test_collector
59+
```
60+
61+
[1]: https://help.sumologic.com/03Send-Data/Installed-Collectors/01About-Installed-Collectors
62+
[2]: https://en.wikipedia.org/wiki/Tz_database
63+
[3]: https://help.sumologic.com/Manage/Fields
64+
[4]: https://www.terraform.io/docs/configuration/resources.html#prevent_destroy
65+
[5]:https://help.sumologic.com/03Send-Data/Installed-Collectors/05Reference-Information-for-Collector-Installation/11Set-a-Collector-as-Ephemeral

0 commit comments

Comments
 (0)