Skip to content

Commit adeaad1

Browse files
authored
T-16278 Add terraform for Better Stack Collectors (#52)
1 parent c75ecc9 commit adeaad1

File tree

18 files changed

+3784
-24
lines changed

18 files changed

+3784
-24
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
strategy:
3030
matrix:
3131
terraform-version: ["0.13", "1.0", "1.8", "latest"]
32-
config: [examples/basic, examples/advanced, examples/connection, examples/scrape, examples/warehouse]
32+
config: [examples/basic, examples/advanced, examples/connection, examples/scrape, examples/warehouse, examples/collector]
3333
fail-fast: false
3434
runs-on: ubuntu-latest
3535
steps:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ GOLANGCI_LINT := golangci-lint run --disable-all \
88
-E staticcheck \
99
-E typecheck \
1010
-E unused
11-
VERSION := 0.7.7
11+
VERSION := 0.8.0
1212
.PHONY: test build
1313

1414
help:

docs/data-sources/collector.md

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "logtail_collector Data Source - terraform-provider-logtail"
4+
subcategory: ""
5+
description: |-
6+
This Data Source allows you to look up existing Collectors by name.
7+
---
8+
9+
# logtail_collector (Data Source)
10+
11+
This Data Source allows you to look up existing Collectors by name.
12+
13+
## Example Usage
14+
15+
```terraform
16+
data "logtail_collector" "production" {
17+
name = "Production Docker"
18+
}
19+
```
20+
21+
<!-- schema generated by tfplugindocs -->
22+
## Schema
23+
24+
### Required
25+
26+
- `name` (String) The name of this collector.
27+
28+
### Read-Only
29+
30+
- `configuration` (List of Object) Collector-level configuration including active components, sampling rates, batching, and VRL transformations. These settings run on the collector host inside your infrastructure. (see [below for nested schema](#nestedatt--configuration))
31+
- `created_at` (String) The time when this collector was created.
32+
- `custom_bucket` (List of Object) Optional custom bucket configuration for the collector. Once set, it cannot be removed. (see [below for nested schema](#nestedatt--custom_bucket))
33+
- `data_region` (String) Data region (e.g. `eu`, `us`) or private cluster name to create the collector in. This can only be set at creation time. Note: the API may return a different identifier (the internal storage region name) than the value you provided.
34+
- `databases` (List of Object) Database connections for the collector. (see [below for nested schema](#nestedatt--databases))
35+
- `databases_count` (Number) The number of database connections configured for this collector.
36+
- `hosts_count` (Number) The number of hosts connected to this collector.
37+
- `hosts_up_count` (Number) The number of hosts currently online.
38+
- `id` (String) The ID of this collector.
39+
- `ingesting_paused` (Boolean) Whether ingestion is paused for this collector.
40+
- `live_tail_pattern` (String) Freeform text template for formatting Live tail output with columns wrapped in {column} brackets. Example: "PID: {message_json.pid} {level} {message}"
41+
- `logs_retention` (Number) Data retention for logs in days. Allowed values: 7, 30, 60, 90, 180, 365, 730, 1095, 1460, 1825. There might be additional charges for longer retention.
42+
- `metrics_retention` (Number) Data retention for metrics in days. Allowed values: 7, 30, 60, 90, 180, 365, 730, 1095, 1460, 1825. There might be additional charges for longer retention.
43+
- `note` (String) A description or note about this collector.
44+
- `pinged_at` (String) The time when this collector last received data.
45+
- `platform` (String) The platform of this collector. This value can be set only when creating a new collector and cannot be changed later. Valid values are: `docker`, `swarm`, `kubernetes`, `proxy`.
46+
- `proxy_config` (List of Object) Proxy settings including buffering proxy, SSL/TLS, and HTTP Basic Authentication. Only applicable to `proxy` platform collectors. (see [below for nested schema](#nestedatt--proxy_config))
47+
- `secret` (String, Sensitive) The secret token used to authenticate collector hosts.
48+
- `source_group_id` (Number) The ID of the source group (folder) this collector belongs to. Set to `0` to remove from a group.
49+
- `source_id` (Number) The ID of the underlying source. Use this with `logtail_metric` to define metrics on this collector's data.
50+
- `source_vrl_transformation` (String) Server-side VRL transformation that runs during ingestion on Better Stack. Use this for enrichment, routing, or light normalization that doesn't involve sensitive data. For PII redaction and sensitive data filtering, prefer `configuration.vrl_transformation` which runs on the collector host and ensures raw data never leaves your network. Read more about [VRL transformations](https://betterstack.com/docs/logs/using-logtail/transforming-ingested-data/logs-vrl/).
51+
- `status` (String) The current status of this collector.
52+
- `team_id` (String) The team ID for this resource.
53+
- `team_name` (String) Used to specify the team the resource should be created in when using global tokens.
54+
- `updated_at` (String) The time when this collector was last updated.
55+
- `user_vector_config` (String) Custom Vector YAML configuration for additional sources and transforms beyond the built-in component toggles. Must not contain `command:` directives.
56+
57+
<a id="nestedatt--configuration"></a>
58+
### Nested Schema for `configuration`
59+
60+
Read-Only:
61+
62+
- `components` (List of Object) (see [below for nested schema](#nestedobjatt--configuration--components))
63+
- `disk_batch_size_mb` (Number)
64+
- `logs_sample_rate` (Number)
65+
- `memory_batch_size_mb` (Number)
66+
- `namespace_option` (Set of Object) (see [below for nested schema](#nestedobjatt--configuration--namespace_option))
67+
- `service_option` (Set of Object) (see [below for nested schema](#nestedobjatt--configuration--service_option))
68+
- `traces_sample_rate` (Number)
69+
- `vrl_transformation` (String)
70+
71+
<a id="nestedobjatt--configuration--components"></a>
72+
### Nested Schema for `configuration.components`
73+
74+
Read-Only:
75+
76+
- `ebpf_metrics` (Boolean)
77+
- `ebpf_tracing_basic` (Boolean)
78+
- `ebpf_tracing_full` (Boolean)
79+
- `logs_collector_internals` (Boolean)
80+
- `logs_docker` (Boolean)
81+
- `logs_host` (Boolean)
82+
- `logs_kubernetes` (Boolean)
83+
- `metrics_apache` (Boolean)
84+
- `metrics_databases` (Boolean)
85+
- `metrics_nginx` (Boolean)
86+
87+
88+
<a id="nestedobjatt--configuration--namespace_option"></a>
89+
### Nested Schema for `configuration.namespace_option`
90+
91+
Read-Only:
92+
93+
- `ingest_traces` (Boolean)
94+
- `log_sampling` (Number)
95+
- `name` (String)
96+
97+
98+
<a id="nestedobjatt--configuration--service_option"></a>
99+
### Nested Schema for `configuration.service_option`
100+
101+
Read-Only:
102+
103+
- `ingest_traces` (Boolean)
104+
- `log_sampling` (Number)
105+
- `name` (String)
106+
107+
108+
109+
<a id="nestedatt--custom_bucket"></a>
110+
### Nested Schema for `custom_bucket`
111+
112+
Read-Only:
113+
114+
- `access_key_id` (String)
115+
- `endpoint` (String)
116+
- `keep_data_after_retention` (Boolean)
117+
- `name` (String)
118+
- `secret_access_key` (String)
119+
120+
121+
<a id="nestedatt--databases"></a>
122+
### Nested Schema for `databases`
123+
124+
Read-Only:
125+
126+
- `host` (String)
127+
- `id` (Number)
128+
- `password` (String)
129+
- `port` (Number)
130+
- `service_type` (String)
131+
- `ssl_mode` (String)
132+
- `tls` (String)
133+
- `username` (String)
134+
135+
136+
<a id="nestedatt--proxy_config"></a>
137+
### Nested Schema for `proxy_config`
138+
139+
Read-Only:
140+
141+
- `buffering_proxy_listen_on` (String)
142+
- `enable_buffering_proxy` (Boolean)
143+
- `enable_http_basic_auth` (Boolean)
144+
- `enable_ssl_certificate` (Boolean)
145+
- `http_basic_auth_password` (String)
146+
- `http_basic_auth_username` (String)
147+
- `ssl_certificate_host` (String)

docs/data-sources/source.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ This Data Source allows you to look up existing Sources using their table name.
9393
- `team_name` (String) Used to specify the team the resource should be created in when using global tokens.
9494
- `token` (String) The token of this source. This token is used to identify and route the data you will send to Better Stack.
9595
- `updated_at` (String) The time when this monitor group was updated.
96-
- `vrl_transformation` (String) The VRL code that's used to transform events. Read more about [VRL transformations](https://betterstack.com/docs/logs/using-logtail/transforming-ingested-data/logs-vrl/).
96+
- `vrl_transformation` (String) VRL transformation that runs on Better Stack's servers during ingestion. Note: data has already left your infrastructure at this point. For transformations that must run before data leaves your network (e.g. PII redaction), use `logtail_collector` with `configuration.vrl_transformation` instead. Read more about [VRL transformations](https://betterstack.com/docs/logs/using-logtail/transforming-ingested-data/logs-vrl/).
9797

9898
<a id="nestedatt--custom_bucket"></a>
9999
### Nested Schema for `custom_bucket`

docs/resources/collector.md

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "logtail_collector Resource - terraform-provider-logtail"
4+
subcategory: ""
5+
description: |-
6+
This resource allows you to create, modify, and delete Better Stack Collectors. For more information about the Collectors API check https://betterstack.com/docs/logs/api/collectors/
7+
---
8+
9+
# logtail_collector (Resource)
10+
11+
This resource allows you to create, modify, and delete Better Stack Collectors. For more information about the Collectors API check https://betterstack.com/docs/logs/api/collectors/
12+
13+
## Example Usage
14+
15+
```terraform
16+
# Collector with dual-layer VRL: on-host PII redaction + server-side enrichment
17+
resource "logtail_collector" "production" {
18+
name = "Production Docker"
19+
platform = "docker"
20+
note = "Docker hosts with PII redaction for GDPR compliance"
21+
22+
logs_retention = 30
23+
metrics_retention = 90
24+
25+
# On-host VRL runs inside your infrastructure — raw data never leaves your network
26+
configuration {
27+
vrl_transformation = <<-EOT
28+
# Redact e-mail addresses
29+
if is_string(.message) {
30+
.message = replace!(.message, r'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}', "[REDACTED_EMAIL]")
31+
}
32+
# Redact known PII fields
33+
if exists(.user_email) { .user_email = "[REDACTED]" }
34+
if exists(.client_ip) { .client_ip = "[REDACTED]" }
35+
EOT
36+
37+
components {
38+
logs_host = true
39+
logs_docker = true
40+
ebpf_metrics = true
41+
}
42+
}
43+
44+
# Server-side VRL runs during ingestion on Better Stack
45+
source_vrl_transformation = <<-EOT
46+
.environment = "production"
47+
.compliance_redacted = true
48+
EOT
49+
}
50+
```
51+
52+
<!-- schema generated by tfplugindocs -->
53+
## Schema
54+
55+
### Required
56+
57+
- `name` (String) The name of this collector.
58+
- `platform` (String) The platform of this collector. This value can be set only when creating a new collector and cannot be changed later. Valid values are: `docker`, `swarm`, `kubernetes`, `proxy`.
59+
60+
### Optional
61+
62+
- `configuration` (Block List, Max: 1) Collector-level configuration including active components, sampling rates, batching, and VRL transformations. These settings run on the collector host inside your infrastructure. (see [below for nested schema](#nestedblock--configuration))
63+
- `custom_bucket` (Block List, Max: 1) Optional custom bucket configuration for the collector. Once set, it cannot be removed. (see [below for nested schema](#nestedblock--custom_bucket))
64+
- `data_region` (String) Data region (e.g. `eu`, `us`) or private cluster name to create the collector in. This can only be set at creation time. Note: the API may return a different identifier (the internal storage region name) than the value you provided.
65+
- `databases` (Block List) Database connections for the collector. (see [below for nested schema](#nestedblock--databases))
66+
- `ingesting_paused` (Boolean) Whether ingestion is paused for this collector.
67+
- `live_tail_pattern` (String) Freeform text template for formatting Live tail output with columns wrapped in {column} brackets. Example: "PID: {message_json.pid} {level} {message}"
68+
- `logs_retention` (Number) Data retention for logs in days. Allowed values: 7, 30, 60, 90, 180, 365, 730, 1095, 1460, 1825. There might be additional charges for longer retention.
69+
- `metrics_retention` (Number) Data retention for metrics in days. Allowed values: 7, 30, 60, 90, 180, 365, 730, 1095, 1460, 1825. There might be additional charges for longer retention.
70+
- `note` (String) A description or note about this collector.
71+
- `proxy_config` (Block List, Max: 1) Proxy settings including buffering proxy, SSL/TLS, and HTTP Basic Authentication. Only applicable to `proxy` platform collectors. (see [below for nested schema](#nestedblock--proxy_config))
72+
- `source_group_id` (Number) The ID of the source group (folder) this collector belongs to. Set to `0` to remove from a group.
73+
- `source_vrl_transformation` (String) Server-side VRL transformation that runs during ingestion on Better Stack. Use this for enrichment, routing, or light normalization that doesn't involve sensitive data. For PII redaction and sensitive data filtering, prefer `configuration.vrl_transformation` which runs on the collector host and ensures raw data never leaves your network. Read more about [VRL transformations](https://betterstack.com/docs/logs/using-logtail/transforming-ingested-data/logs-vrl/).
74+
- `team_name` (String) Used to specify the team the resource should be created in when using global tokens.
75+
- `user_vector_config` (String) Custom Vector YAML configuration for additional sources and transforms beyond the built-in component toggles. Must not contain `command:` directives.
76+
77+
### Read-Only
78+
79+
- `created_at` (String) The time when this collector was created.
80+
- `databases_count` (Number) The number of database connections configured for this collector.
81+
- `hosts_count` (Number) The number of hosts connected to this collector.
82+
- `hosts_up_count` (Number) The number of hosts currently online.
83+
- `id` (String) The ID of this collector.
84+
- `pinged_at` (String) The time when this collector last received data.
85+
- `secret` (String, Sensitive) The secret token used to authenticate collector hosts.
86+
- `source_id` (Number) The ID of the underlying source. Use this with `logtail_metric` to define metrics on this collector's data.
87+
- `status` (String) The current status of this collector.
88+
- `team_id` (String) The team ID for this resource.
89+
- `updated_at` (String) The time when this collector was last updated.
90+
91+
<a id="nestedblock--configuration"></a>
92+
### Nested Schema for `configuration`
93+
94+
Optional:
95+
96+
- `components` (Block List, Max: 1) Enable or disable specific collector components. Maps to the Logs, Metrics, and eBPF tabs in the collector settings UI. (see [below for nested schema](#nestedblock--configuration--components))
97+
- `disk_batch_size_mb` (Number) Disk buffer size in MB for outgoing requests. Minimum 256 MB.
98+
- `logs_sample_rate` (Number) Sample rate for logs (0-100).
99+
- `memory_batch_size_mb` (Number) Memory batch size in MB for outgoing requests. Maximum 40 MB.
100+
- `namespace_option` (Block Set) Per-namespace overrides for log sampling rate and trace ingestion (Kubernetes only). Order-independent; entries are identified by name. (see [below for nested schema](#nestedblock--configuration--namespace_option))
101+
- `service_option` (Block Set) Per-service overrides for log sampling rate and trace ingestion. Only includes user-managed services; internal collector services (`better-stack-beyla`, `better-stack-collector`) are excluded. Use the `logtail_collector` data source to see all discovered services. (see [below for nested schema](#nestedblock--configuration--service_option))
102+
- `traces_sample_rate` (Number) Sample rate for traces (0-100).
103+
- `vrl_transformation` (String) VRL transformation that runs on the collector host, inside your infrastructure, before data is transmitted to Better Stack. Use this for PII redaction and sensitive data filtering — raw data never leaves your network. For server-side transformations that run during ingestion on Better Stack, use the top-level `source_vrl_transformation` attribute instead. Read more about [VRL transformations](https://betterstack.com/docs/logs/using-logtail/transforming-ingested-data/logs-vrl/).
104+
105+
<a id="nestedblock--configuration--components"></a>
106+
### Nested Schema for `configuration.components`
107+
108+
Optional:
109+
110+
- `ebpf_metrics` (Boolean) Enable eBPF-based metrics collection.
111+
- `ebpf_tracing_basic` (Boolean) Enable basic eBPF tracing.
112+
- `ebpf_tracing_full` (Boolean) Enable full eBPF tracing.
113+
- `logs_collector_internals` (Boolean) Collect internal collector logs.
114+
- `logs_docker` (Boolean) Collect Docker container logs.
115+
- `logs_host` (Boolean) Collect host-level logs.
116+
- `logs_kubernetes` (Boolean) Collect Kubernetes logs.
117+
- `metrics_apache` (Boolean) Collect Apache metrics.
118+
- `metrics_databases` (Boolean) Collect database metrics via the cluster agent.
119+
- `metrics_nginx` (Boolean) Collect Nginx metrics.
120+
121+
122+
<a id="nestedblock--configuration--namespace_option"></a>
123+
### Nested Schema for `configuration.namespace_option`
124+
125+
Required:
126+
127+
- `name` (String) Namespace name.
128+
129+
Optional:
130+
131+
- `ingest_traces` (Boolean) Whether to ingest traces for this namespace.
132+
- `log_sampling` (Number) Log sampling rate (0-100).
133+
134+
135+
<a id="nestedblock--configuration--service_option"></a>
136+
### Nested Schema for `configuration.service_option`
137+
138+
Required:
139+
140+
- `name` (String) Service name.
141+
142+
Optional:
143+
144+
- `ingest_traces` (Boolean) Whether to ingest traces for this service.
145+
- `log_sampling` (Number) Log sampling rate (0-100).
146+
147+
148+
149+
<a id="nestedblock--custom_bucket"></a>
150+
### Nested Schema for `custom_bucket`
151+
152+
Required:
153+
154+
- `access_key_id` (String) Access key ID for the bucket.
155+
- `endpoint` (String) Bucket endpoint URL.
156+
- `name` (String) Bucket name.
157+
- `secret_access_key` (String, Sensitive) Secret access key for the bucket.
158+
159+
Optional:
160+
161+
- `keep_data_after_retention` (Boolean) Whether to keep data in the bucket after the retention period.
162+
163+
164+
<a id="nestedblock--databases"></a>
165+
### Nested Schema for `databases`
166+
167+
Required:
168+
169+
- `host` (String) The database host.
170+
- `port` (Number) The database port.
171+
- `service_type` (String) The type of database service.
172+
173+
Optional:
174+
175+
- `password` (String, Sensitive) The database password.
176+
- `ssl_mode` (String) SSL mode for PostgreSQL connections. Valid values: `disable`, `require`, `verify-ca`.
177+
- `tls` (String) TLS mode for MySQL connections. Valid values: `false`, `true`, `skip-verify`, `preferred`.
178+
- `username` (String) The database username.
179+
180+
Read-Only:
181+
182+
- `id` (Number) The ID of this database connection (assigned by the API).
183+
184+
185+
<a id="nestedblock--proxy_config"></a>
186+
### Nested Schema for `proxy_config`
187+
188+
Optional:
189+
190+
- `buffering_proxy_listen_on` (String) Address and port for the buffering proxy to listen on.
191+
- `enable_buffering_proxy` (Boolean) Enable the HTTP buffering proxy for the collector.
192+
- `enable_http_basic_auth` (Boolean) Enable HTTP Basic Authentication for the collector proxy.
193+
- `enable_ssl_certificate` (Boolean) Enable custom SSL/TLS certificate for the collector.
194+
- `http_basic_auth_password` (String, Sensitive) Password for HTTP Basic Authentication. This value is write-only and never returned by the API.
195+
- `http_basic_auth_username` (String) Username for HTTP Basic Authentication.
196+
- `ssl_certificate_host` (String) Hostname for the SSL certificate.

docs/resources/source.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ This resource allows you to create, modify, and delete your Sources. For more in
8686
- `scrape_urls` (List of String) For scrape platform types, the set of urls to scrape.
8787
- `source_group_id` (Number) The ID of the source group this source belongs to.
8888
- `team_name` (String) Used to specify the team the resource should be created in when using global tokens.
89-
- `vrl_transformation` (String) The VRL code that's used to transform events. Read more about [VRL transformations](https://betterstack.com/docs/logs/using-logtail/transforming-ingested-data/logs-vrl/).
89+
- `vrl_transformation` (String) VRL transformation that runs on Better Stack's servers during ingestion. Note: data has already left your infrastructure at this point. For transformations that must run before data leaves your network (e.g. PII redaction), use `logtail_collector` with `configuration.vrl_transformation` instead. Read more about [VRL transformations](https://betterstack.com/docs/logs/using-logtail/transforming-ingested-data/logs-vrl/).
9090

9191
### Read-Only
9292

0 commit comments

Comments
 (0)