Files
fleet-terraform/addons/byo-cloudwatch-log-sharing/target-account-firehose/README.md
T

8.6 KiB

Fleet CloudWatch Log Group Sharing via Firehose (Target Account)

This module creates the cross-account CloudWatch Logs destination and a Firehose delivery stream target.

CloudWatch Logs subscription payloads are already gzip-compressed. This module defaults Firehose compression_format to UNCOMPRESSED to avoid double-compression.

Because CloudWatch Logs destinations must be created in the same region as the source log group, this module uses two provider aliases:

  • aws.destination: Region of the Fleet CloudWatch log group (source region).
  • aws.target: Region for the Firehose stream and S3 bucket (same region or different region).

Both provider aliases must use the same AWS account credentials. Cross-account is achieved between source and target subscriptions, not between aws.destination and aws.target within this module.

Usage

provider "aws" {
  alias  = "source_region"
  region = "us-east-2"
}

provider "aws" {
  alias  = "target_region"
  region = "us-west-2"
}

module "fleet_log_sharing_target" {
  source = "github.com/fleetdm/fleet-terraform//addons/byo-cloudwatch-log-sharing/target-account-firehose?depth=1&ref=tf-mod-addon-byo-cloudwatch-log-sharing-v1.0.0"

  providers = {
    aws.destination = aws.source_region
    aws.target      = aws.target_region
  }

  source_account_ids = ["111111111111"]

  cloudwatch_destination = {
    name        = "fleet-app-logs-firehose"
    role_name   = "fleet-app-logs-destination-role"
    policy_name = "fleet-app-logs-destination-policy"
  }

  firehose = {
    delivery_stream_name = "fleet-app-logs-firehose"
    role_name            = "fleet-app-logs-firehose-role"
    policy_name          = "fleet-app-logs-firehose-policy"
    # Optional override; default is UNCOMPRESSED.
    compression_format   = "UNCOMPRESSED"
  }

  s3 = {
    bucket_name = "fleet-app-logs-firehose-example"
  }
}

output "fleet_log_sharing_target" {
  value = module.fleet_log_sharing_target
}

Then apply the source account module (../cloudwatch) using module.fleet_log_sharing_target.log_destination.arn (default destination_type is firehose).

Requirements

Name Version
terraform >= 1.3.7
aws >= 5.29.0

Providers

Name Version
aws >= 5.29.0
aws.destination >= 5.29.0
aws.target >= 5.29.0

Modules

No modules.

Resources

Name Type
aws_cloudwatch_log_destination.destination resource
aws_cloudwatch_log_destination_policy.destination resource
aws_iam_policy.destination resource
aws_iam_policy.firehose resource
aws_iam_role.destination resource
aws_iam_role.firehose resource
aws_iam_role_policy_attachment.destination resource
aws_iam_role_policy_attachment.firehose resource
aws_kinesis_firehose_delivery_stream.destination resource
aws_s3_bucket.destination resource
aws_s3_bucket_public_access_block.destination resource
aws_s3_bucket_server_side_encryption_configuration.destination resource
aws_caller_identity.destination data source
aws_caller_identity.target data source
aws_iam_policy_document.assume_role data source
aws_iam_policy_document.destination data source
aws_iam_policy_document.destination_policy data source
aws_iam_policy_document.firehose data source
aws_iam_policy_document.firehose_assume_role data source
aws_partition.destination data source
aws_region.destination data source
aws_region.target data source

Inputs

Name Description Type Default Required
cloudwatch_destination CloudWatch Logs destination settings in the source log-group region.
object({
name = optional(string, "fleet-log-sharing-firehose-destination")
role_name = optional(string, "fleet-log-sharing-firehose-destination-role")
policy_name = optional(string)
})
{} no
destination_policy_source_organization_id Optional AWS Organization ID allowed to subscribe to this destination. string "" no
firehose Firehose delivery stream settings used as the CloudWatch Logs destination target. CloudWatch Logs subscription payloads are already gzip-compressed, so UNCOMPRESSED is the default to avoid double compression.
object({
delivery_stream_name = string
role_name = optional(string, "fleet-log-sharing-firehose-delivery-role")
policy_name = optional(string)
buffering_size = optional(number, 5)
buffering_interval = optional(number, 300)
compression_format = optional(string, "UNCOMPRESSED")
s3_prefix = optional(string, "fleet-logs/year=!{timestamp:yyyy}/month=!{timestamp:MM}/day=!{timestamp:dd}/")
s3_error_prefix = optional(string, "fleet-logs-errors/!{firehose:error-output-type}/year=!{timestamp:yyyy}/month=!{timestamp:MM}/day=!{timestamp:dd}/")
})
n/a yes
s3 S3 configuration for Firehose delivered logs.
object({
bucket_name = string
force_destroy = optional(bool, false)
})
n/a yes
source_account_ids AWS account IDs allowed to create subscription filters to this destination. list(string) n/a yes
tags Tags to apply to created resources that support tags. map(string) {} no

Outputs

Name Description
firehose Firehose destination details.
log_destination CloudWatch Logs destination details to share with the source-account team.
s3_bucket S3 bucket details used as the Firehose destination.