Skip to content

Commit 971fb52

Browse files
committed
Feature: Add support for logstash output
1 parent 44991c9 commit 971fb52

File tree

6 files changed

+126
-11
lines changed

6 files changed

+126
-11
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ You can install libc6-compat using ``apk add --no-cache libc6-compat``.
1717

1818
## Simple example ##
1919

20-
For detailed example please refer to this [blog post](https://medium.com/@pascal-euhus/terraform-functionbeat-e481554d729e)
20+
For detailed example please refer to this [blog post](https://medium.com/@pascal-euhus/terraform-functionbeat-e481554d729e) using Elasticsearch output
21+
Please note that output to Logstash is also possible, but in this example we
22+
use Elasticsearch.
2123

2224
````terraform
2325
resource "aws_security_group" "functionbeat_securitygroup" {
@@ -59,7 +61,7 @@ module "functionbeat" {
5961

6062
## Advanced example ##
6163

62-
Head over to `example/main.tf` to get an more advanced example.
64+
Head over to `example/elasticsearch.tf` to get an more advanced example.
6365

6466
## Usage ##
6567

@@ -94,10 +96,10 @@ You configure your lambda here.
9496
}
9597
# You can put any HCL-Map with valid Functionbeat config for Elasticsearch Output
9698
output_elasticsearch = {
97-
hosts : ["https://your-endpoint:443"]
98-
protocol : "https"
99-
username : "elastic"
100-
password : "mysupersecret"
99+
hosts = ["https://your-endpoint:443"]
100+
protocol = "https"
101+
username = "elastic"
102+
password = "mysupersecret"
101103
}
102104
}
103105
````

examples/main.tf renamed to examples/elasticsearch.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ module "functionbeat" {
5353
}
5454

5555
output_elasticsearch = {
56-
hosts : ["https://your-endpoint:443"]
57-
protocol : "https"
58-
username : "elastic"
59-
password : "mysupersecret"
56+
hosts = ["https://your-endpoint:443"]
57+
protocol = "https"
58+
username = "elastic"
59+
password = "mysupersecret"
6060
}
61+
6162
}
6263

6364
loggroup_name = aws_cloudwatch_log_group.example_logs.name

examples/logstash.tf

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
provider "aws" {
2+
max_retries = 1337
3+
region = "eu-central-1"
4+
}
5+
6+
resource "aws_vpc" "vpc" {
7+
cidr_block = "172.16.0.0/16"
8+
tags = {
9+
Name = "Test-VPC"
10+
}
11+
}
12+
13+
resource "aws_subnet" "subnet" {
14+
vpc_id = aws_vpc.vpc.id
15+
cidr_block = cidrsubnet(aws_vpc.vpc.cidr_block, 8, 10)
16+
availability_zone = "eu-central-1a"
17+
tags = {
18+
Name = "Private"
19+
}
20+
}
21+
22+
resource "aws_cloudwatch_log_group" "example_logs" {
23+
name = "MyExampleService"
24+
retention_in_days = 1
25+
}
26+
27+
resource "aws_security_group" "functionbeat_securitygroup" {
28+
name = "Functionbeat"
29+
vpc_id = aws_vpc.vpc.id
30+
31+
egress {
32+
from_port = 443
33+
protocol = "tcp"
34+
to_port = 443
35+
description = "HTTPS"
36+
cidr_blocks = ["0.0.0.0/0"]
37+
}
38+
}
39+
40+
module "functionbeat" {
41+
source = "../"
42+
43+
application_name = "crazy-test-module"
44+
functionbeat_version = "7.17.1"
45+
46+
lambda_config = {
47+
name = "my-kibana-exporter"
48+
49+
vpc_config = {
50+
vpc_id = aws_vpc.vpc.id
51+
subnet_ids = [aws_subnet.subnet.id]
52+
security_group_ids = [aws_security_group.functionbeat_securitygroup.id]
53+
}
54+
55+
output_logstash = {
56+
hosts = ["10.0.0.1:5044", "10.0.0.2:5044"]
57+
ssl.enabled = false
58+
}
59+
}
60+
61+
loggroup_name = aws_cloudwatch_log_group.example_logs.name
62+
63+
fb_extra_configuration = {
64+
fields = {
65+
env = "test",
66+
foo = "bar"
67+
}
68+
setup = {
69+
"template.settings" = {
70+
"index.number_of_shards" : 1
71+
}
72+
ilm = {
73+
enabled : true
74+
rollover_alias : "my-alias"
75+
pattern : "{now/d}-000001"
76+
policy_name : "index_curation"
77+
}
78+
}
79+
logging = {
80+
to_syslog : false
81+
to_eventlog : false
82+
}
83+
processors = [
84+
{
85+
add_cloud_metadata : null
86+
},
87+
{
88+
add_fields = {
89+
fields = {
90+
id = "574734885120952459"
91+
name = "myproject"
92+
}
93+
target = "project"
94+
}
95+
}
96+
]
97+
}
98+
fb_extra_tags = ["webserver", "testme"]
99+
}

file/functionbeat.yml.tftpl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,22 @@ ${yamlencode({
2525
# Configure what output to use when sending the data collected by the beat.
2626

2727
# ---------------------------- Elasticsearch Output ----------------------------
28+
29+
%{ if output_elasticsearch != null }
2830
${yamlencode({
2931
output = {
3032
elasticsearch = output_elasticsearch
3133
}
3234
})}
35+
%{ endif }
36+
37+
%{ if output_logstash != null }
38+
${yamlencode({
39+
output = {
40+
logstash = output_logstash
41+
}
42+
})}
43+
%{ endif }
3344

3445
# ================================== Logging ===================================
3546

main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ resource "local_file" "functionbeat_config" {
1313
enabled_function_name = var.lambda_config.name
1414
application_name = var.application_name
1515
output_elasticsearch = var.lambda_config.output_elasticsearch
16+
output_logstash = var.lambda_config.output_logstash
1617
fb_transaction_tags = var.fb_extra_tags
1718
fb_extra_configuration = var.fb_extra_configuration
1819
})

variables.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ variable "lambda_config" {
1919
subnet_ids = list(string)
2020
security_group_ids = list(string)
2121
})
22-
output_elasticsearch = any
22+
output_elasticsearch = optional(any)
23+
output_logstash = optional(any)
2324
})
2425
}
2526

0 commit comments

Comments
 (0)