Skip to content

Commit

Permalink
Merge pull request #3 from noqqe/main
Browse files Browse the repository at this point in the history
Feature: Add support for logstash output
  • Loading branch information
PacoVK authored Dec 14, 2022
2 parents 44991c9 + 971fb52 commit 3c9fc7b
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 11 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ You can install libc6-compat using ``apk add --no-cache libc6-compat``.

## Simple example ##

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

````terraform
resource "aws_security_group" "functionbeat_securitygroup" {
Expand Down Expand Up @@ -59,7 +61,7 @@ module "functionbeat" {

## Advanced example ##

Head over to `example/main.tf` to get an more advanced example.
Head over to `example/elasticsearch.tf` to get an more advanced example.

## Usage ##

Expand Down Expand Up @@ -94,10 +96,10 @@ You configure your lambda here.
}
# You can put any HCL-Map with valid Functionbeat config for Elasticsearch Output
output_elasticsearch = {
hosts : ["https://your-endpoint:443"]
protocol : "https"
username : "elastic"
password : "mysupersecret"
hosts = ["https://your-endpoint:443"]
protocol = "https"
username = "elastic"
password = "mysupersecret"
}
}
````
Expand Down
9 changes: 5 additions & 4 deletions examples/main.tf → examples/elasticsearch.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ module "functionbeat" {
}

output_elasticsearch = {
hosts : ["https://your-endpoint:443"]
protocol : "https"
username : "elastic"
password : "mysupersecret"
hosts = ["https://your-endpoint:443"]
protocol = "https"
username = "elastic"
password = "mysupersecret"
}

}

loggroup_name = aws_cloudwatch_log_group.example_logs.name
Expand Down
99 changes: 99 additions & 0 deletions examples/logstash.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
provider "aws" {
max_retries = 1337
region = "eu-central-1"
}

resource "aws_vpc" "vpc" {
cidr_block = "172.16.0.0/16"
tags = {
Name = "Test-VPC"
}
}

resource "aws_subnet" "subnet" {
vpc_id = aws_vpc.vpc.id
cidr_block = cidrsubnet(aws_vpc.vpc.cidr_block, 8, 10)
availability_zone = "eu-central-1a"
tags = {
Name = "Private"
}
}

resource "aws_cloudwatch_log_group" "example_logs" {
name = "MyExampleService"
retention_in_days = 1
}

resource "aws_security_group" "functionbeat_securitygroup" {
name = "Functionbeat"
vpc_id = aws_vpc.vpc.id

egress {
from_port = 443
protocol = "tcp"
to_port = 443
description = "HTTPS"
cidr_blocks = ["0.0.0.0/0"]
}
}

module "functionbeat" {
source = "../"

application_name = "crazy-test-module"
functionbeat_version = "7.17.1"

lambda_config = {
name = "my-kibana-exporter"

vpc_config = {
vpc_id = aws_vpc.vpc.id
subnet_ids = [aws_subnet.subnet.id]
security_group_ids = [aws_security_group.functionbeat_securitygroup.id]
}

output_logstash = {
hosts = ["10.0.0.1:5044", "10.0.0.2:5044"]
ssl.enabled = false
}
}

loggroup_name = aws_cloudwatch_log_group.example_logs.name

fb_extra_configuration = {
fields = {
env = "test",
foo = "bar"
}
setup = {
"template.settings" = {
"index.number_of_shards" : 1
}
ilm = {
enabled : true
rollover_alias : "my-alias"
pattern : "{now/d}-000001"
policy_name : "index_curation"
}
}
logging = {
to_syslog : false
to_eventlog : false
}
processors = [
{
add_cloud_metadata : null
},
{
add_fields = {
fields = {
id = "574734885120952459"
name = "myproject"
}
target = "project"
}
}
]
}
fb_extra_tags = ["webserver", "testme"]
}
11 changes: 11 additions & 0 deletions file/functionbeat.yml.tftpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,22 @@ ${yamlencode({
# Configure what output to use when sending the data collected by the beat.

# ---------------------------- Elasticsearch Output ----------------------------

%{ if output_elasticsearch != null }
${yamlencode({
output = {
elasticsearch = output_elasticsearch
}
})}
%{ endif }

%{ if output_logstash != null }
${yamlencode({
output = {
logstash = output_logstash
}
})}
%{ endif }

# ================================== Logging ===================================

Expand Down
1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ resource "local_file" "functionbeat_config" {
enabled_function_name = var.lambda_config.name
application_name = var.application_name
output_elasticsearch = var.lambda_config.output_elasticsearch
output_logstash = var.lambda_config.output_logstash
fb_transaction_tags = var.fb_extra_tags
fb_extra_configuration = var.fb_extra_configuration
})
Expand Down
3 changes: 2 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ variable "lambda_config" {
subnet_ids = list(string)
security_group_ids = list(string)
})
output_elasticsearch = any
output_elasticsearch = optional(any)
output_logstash = optional(any)
})
}

Expand Down

0 comments on commit 3c9fc7b

Please sign in to comment.