Skip to content

Commit

Permalink
Merge pull request #88 from axiomhq/fix/misc-fixes
Browse files Browse the repository at this point in the history
Style suggestions
  • Loading branch information
pecigonzalo authored Oct 7, 2024
2 parents 6f486c2 + 9574797 commit 8b27324
Show file tree
Hide file tree
Showing 15 changed files with 149 additions and 241 deletions.
1 change: 1 addition & 0 deletions examples/forwarder-tf-module/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.terraform.lock.hcl
66 changes: 0 additions & 66 deletions examples/forwarder-tf-module/.terraform.lock.hcl

This file was deleted.

3 changes: 1 addition & 2 deletions examples/forwarder-tf-module/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
resource "axiom_dataset" "lambda_forwarder" {
name = "cloudwatch-lambda"
description = "[islam] test"
description = "Test"
}

module "forwarder" {
Expand All @@ -22,7 +22,6 @@ module "listener" {
prefix = "axiom-cloudwatch-tf-test"
forwarder_lambda_arn = module.forwarder.lambda_arn
log_groups_prefix = "/aws/lambda/"
enable_cloudtrail = false
}

output "log_group_names" {
Expand Down
8 changes: 4 additions & 4 deletions modules/forwarder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Forward logs from AWS Cloudwatch to Axiom.

```hcl
module "forwarder" {
source = "https://github.com/axiomhq/axiom-cloudwatch-forwarder/tree/main/modules/forwarder"
prefix = "axiom-cloudwatch-forwarder"
axiom_dataset = "DATASET_NAME"
axiom_token = "xaat-***"
source = "https://github.com/axiomhq/axiom-cloudwatch-forwarder/tree/main/modules/forwarder"
prefix = "axiom-cloudwatch-forwarder"
axiom_dataset = "DATASET_NAME"
axiom_token = "xaat-***"
}
```
5 changes: 2 additions & 3 deletions modules/forwarder/forwarder.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
resource "aws_lambda_function" "forwarder" {
s3_bucket = var.forwarder_bucket
s3_key = "axiom-cloudwatch-forwarder/v${var.forwarder_version}/forwarder.zip"
s3_bucket = var.lambda_zip_bucket
s3_key = "axiom-cloudwatch-forwarder/v${var.lambda_zip_version}/forwarder.zip"
function_name = "${var.prefix}-forwarder"
logging_config {
log_format = "JSON"
Expand Down Expand Up @@ -57,7 +57,6 @@ resource "aws_cloudwatch_log_group" "forwarder" {
}
}


resource "aws_lambda_permission" "allow_cloudwatch" {
statement_id = "AllowExecutionFromCloudWatch"
action = "lambda:InvokeFunction"
Expand Down
33 changes: 17 additions & 16 deletions modules/forwarder/variables.tf
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
variable "axiom_dataset" {
variable "prefix" {
type = string
description = "Axiom dataset to forward logs to"
description = "Prefix for resources, defaults to axiom-cloudwatch"
default = "axiom-cloudwatch"
}

variable "axiom_token" {
variable "lambda_zip_bucket" {
type = string
description = "Axiom token for the dataset"
description = "Name of the S3 bucket where Lambda code is stored"
default = "axiom-cloudformation"
}

variable "axiom_url" {
variable "lambda_zip_version" {
type = string
description = "Axiom's API URL"
default = "https://api.axiom.co"
description = "Version of the Axiom Lambda"
default = "1.2.0"
}

variable "prefix" {
variable "axiom_dataset" {
type = string
default = "axiom-cloudwatch"
description = "prefix for resources, defaults to axiom-cloudwatch"
description = "Axiom dataset to forward logs to"
}

variable "forwarder_bucket" {
variable "axiom_token" {
type = string
default = "axiom-cloudformation"
description = "name of the S3 bucket where Forwarder Lambda code is stored"
description = "Axiom token for the dataset"
}

variable "forwarder_version" {
variable "axiom_url" {
type = string
default = "1.2.0"
description = "Version of the Axiom CloudWatch Forwarder Lambda"
description = "Axiom's API URL"
default = "https://api.axiom.co"
}

4 changes: 2 additions & 2 deletions modules/listener/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ This module sets up a lambda function that listens to Cloudwatch logs and subscr

```hcl
module "listener" {
source = "https://github.com/axiomhq/axiom-cloudwatch-forwarder/tree/main/modules/listener"
prefix = "axiom-cloudwatch-forwarder"
source = "https://github.com/axiomhq/axiom-cloudwatch-forwarder/tree/main/modules/listener"
prefix = "axiom-cloudwatch-forwarder"
forwarder_lambda_arn = module.forwarder.lambda_arn
log_groups_prefix = "/aws/lambda/"
}
Expand Down
68 changes: 29 additions & 39 deletions modules/listener/listener.tf
Original file line number Diff line number Diff line change
@@ -1,31 +1,6 @@
data "aws_iam_policy_document" "listener" {
statement {
actions = [
"logs:DescribeSubscriptionFilters",
"logs:DeleteSubscriptionFilter",
"logs:PutSubscriptionFilter",
"logs:DescribeLogGroups",
"logs:CreateLogStream",
"logs:PutLogEvents",
"lambda:AddPermission",
"lambda:RemovePermission",
"lambda:InvokeFunction",
"lambda:GetFunction",
"logs:DescribeLogStreams",
"logs:DescribeSubscriptionFilters",
"logs:FilterLogEvents",
"logs:GetLogEvents",
"logs:CreateLogStream",
"logs:PutLogEvents"
]

resources = ["*"]
}
}

resource "aws_lambda_function" "listener" {
s3_bucket = var.forwarder_bucket
s3_key = "axiom-cloudwatch-forwarder/v${var.forwarder_version}/forwarder.zip"
s3_bucket = var.lambda_zip_bucket
s3_key = "axiom-cloudwatch-forwarder/v${var.lambda_zip_version}/forwarder.zip"
function_name = "${var.prefix}-listener"
description = "Axiom CloudWatch Automatic log groups listener lambda"
logging_config {
Expand Down Expand Up @@ -74,27 +49,42 @@ resource "aws_iam_role" "listener" {
]
})

managed_policy_arns = [
aws_iam_policy.listener.arn
]

tags = {
PartOf = var.prefix
Platform = "Axiom"
Component = "axiom-cloudwatch-listener"
}
}

resource "aws_iam_policy" "listener" {
name = "${var.prefix}-listener-lambda-policy"
path = "/"
policy = data.aws_iam_policy_document.listener.json
tags = {
PartOf = var.prefix
Platform = "Axiom"
Component = "axiom-cloudwatch-listener"
data "aws_iam_policy_document" "listener" {
statement {
actions = [
"logs:DescribeSubscriptionFilters",
"logs:DeleteSubscriptionFilter",
"logs:PutSubscriptionFilter",
"logs:DescribeLogGroups",
"logs:CreateLogStream",
"logs:PutLogEvents",
"lambda:AddPermission",
"lambda:RemovePermission",
"lambda:InvokeFunction",
"lambda:GetFunction",
"logs:DescribeLogStreams",
"logs:DescribeSubscriptionFilters",
"logs:FilterLogEvents",
"logs:GetLogEvents",
"logs:CreateLogStream",
"logs:PutLogEvents"
]

resources = ["*"]
}
}
resource "aws_iam_role_policy" "listener" {
name = "default"
role = aws_iam_role.listener.id
policy = data.aws_iam_policy_document.listener.json
}

resource "aws_cloudwatch_log_group" "listener" {
name = "/aws/axiom/${var.prefix}-listener"
Expand Down
24 changes: 12 additions & 12 deletions modules/listener/variables.tf
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
variable "prefix" {
type = string
default = "axiom-cloudwatch"
description = "prefix for resources, defaults to axiom-cloudwatch"
description = "Prefix for resources, defaults to axiom-cloudwatch"
}

variable "forwarder_lambda_arn" {
variable "lambda_zip_bucket" {
type = string
description = "The ARN of the Lambda function that forwards logs to Axiom"
description = "Name of the S3 bucket where Lambda code is stored"
default = "axiom-cloudformation"
}

variable "log_groups_prefix" {
variable "lambda_zip_version" {
type = string
description = "The prefix of the CloudWatch log groups that will trigger the Axiom CloudWatch Forwarder Lambda."
default = ""
description = "Version of the Axiom Lambda"
default = "1.2.0"
}

variable "forwarder_bucket" {
variable "forwarder_lambda_arn" {
type = string
default = "axiom-cloudformation"
description = "name of the S3 bucket where Forwarder Lambda code is stored"
description = "The ARN of the Lambda function that forwards logs to Axiom"
}

variable "forwarder_version" {
variable "log_groups_prefix" {
type = string
default = "1.2.0"
description = "Version of the Axiom CloudWatch Forwarder Lambda"
description = "The prefix of the CloudWatch log groups that will trigger the Axiom CloudWatch Forwarder Lambda"
default = ""
}
6 changes: 3 additions & 3 deletions modules/subscriber/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Creates a Lambda function that subscribers the Forwarder to AWS Cloudwatch log g

```hcl
module "subscriber" {
source = "https://github.com/axiomhq/axiom-cloudwatch-forwarder/tree/main/modules/subscriber"
prefix = "axiom-cloudwatch-forwarder"
axiom_dataset = "DATASET_NAME"
source = "https://github.com/axiomhq/axiom-cloudwatch-forwarder/tree/main/modules/subscriber"
prefix = "axiom-cloudwatch-forwarder"
axiom_dataset = "DATASET_NAME"
log_groups_prefix = "/aws/lambda/"
forwarder_lambda_arn = module.forwarder.lambda_arn
}
Expand Down
Loading

0 comments on commit 8b27324

Please sign in to comment.