Skip to main content

Component: datadog-logs-archive

This component is responsible for provisioning Datadog Log Archives. It creates a single log archive pipeline for each AWS account. If the catchall flag is set, it creates a catchall archive within the same S3 bucket.

Each log archive filters for the tag env:$env where $env is the environment/account name (ie sbx, prd, tools, etc), as well as any tags identified in the additional_tags key. The catchall archive, as the name implies, filters for '*'.

A second bucket is created for cloudtrail, and a cloudtrail is configured to monitor the log archive bucket and log activity to the cloudtrail bucket. To forward these cloudtrail logs to datadog, the cloudtrail bucket's id must be added to the s3_buckets key for our datadog-lambda-forwarder component.

Both buckets support object lock, with overrideable defaults of COMPLIANCE mode with a duration of 7 days.

Prerequisites

  • Datadog integration set up in target environment
    • We rely on the datadog api and app keys added by our datadog integration component

Issues, Gotchas, Good-to-Knows

Destroy/reprovision process

Because of the protections for S3 buckets, if we want to destroy/replace our bucket, we need to do so in two passes or destroy the bucket manually and then use terraform to clean up the rest. If reprovisioning a recently provisioned bucket, the two-pass process works well. If the bucket has a full day or more of logs, though, deleting it manually first will avoid terraform timeouts, and then the terraform process can be used to clean up everything else.

Two step process to destroy via terraform

  • first set s3_force_destroy var to true and apply
  • next set enabled to false and apply or use tf destroy

Usage

Stack Level: Global

Here's an example snippet for how to use this component. It's suggested to apply this component to all accounts from which Datadog receives logs.

components:
terraform:
datadog-logs-archive:
settings:
spacelift:
workspace_enabled: true
vars:
enabled: true
# additional_query_tags:
# - "forwardername:*-dev-datadog-lambda-forwarder-logs"
# - "account:123456789012"

Requirements

NameVersion
terraform>= 0.13.0
aws>= 2.0
datadog>= 3.3.0
local>= 1.3

Providers

NameVersion
aws>= 2.0
datadog>= 3.7.0
http>= 2.1.0

Modules

NameSourceVersion
cloudtrailcloudposse/cloudtrail/aws0.21.0
cloudtrail_s3_bucketcloudposse/cloudtrail-s3-bucket/aws0.23.1
iam_roles../account-map/modules/iam-rolesn/a
s3_bucketcloudposse/s3-bucket/aws0.46.0
thiscloudposse/label/null0.25.0

Resources

NameType
aws_caller_identity.currentdata source
aws_partition.currentdata source
aws_ssm_parameter.datadog_api_keydata source
aws_ssm_parameter.datadog_app_keydata source
aws_ssm_parameter.datadog_aws_role_namedata source
aws_ssm_parameter.datadog_external_iddata source
datadog_logs_archive.catchall_archiveresource
datadog_logs_archive.logs_archiveresource
http.current_orderdata source

Inputs

NameDescriptionTypeDefaultRequired
additional_query_tagsAdditional tags to include in query for logs for this archivelist[]no
catchallSet to true to enable a catchall for logs unmatched by any queries. This should only be used in one environment/accountboolfalseno
datadog_aws_account_idThe AWS account ID Datadog's integration servers use for all integrationsstring464622532012no
enable_glacier_transitionEnable/disable transition to glacier. Has no effect unless lifecycle_rules_enabled set to truebooltrueno
glacier_transition_daysNumber of days after which to transition objects to glacier storagenumber365no
lifecycle_rules_enabledEnable/disable lifecycle management rules for s3 objectsbooltrueno
object_lock_days_archiveSet duration of archive bucket object locknumber7yes
object_lock_days_cloudtrailSet duration of cloudtrail bucket object locknumber7yes
object_lock_mode_archiveSet mode of archive bucket object lockstringCOMPLIANCEyes
object_lock_mode_cloudtrailSet mode of cloudtrail bucket object lockstringCOMPLIANCEyes
s3_force_destroySet to true to delete non-empty buckets when enabled is set to falseboolfalsefor destroy only

Outputs

NameDescription
archive_idThe ID of the environment-specific log archive
bucket_arnThe ARN of the bucket used for log archive storage
bucket_domain_nameThe FQDN of the bucket used for log archive storage
bucket_idThe ID (name) of the bucket used for log archive storage
bucket_regionThe region of the bucket used for log archive storage
cloudtrail_bucket_arnThe ARN of the bucket used for cloudtrail log storage
cloudtrail_bucket_domain_nameThe FQDN of the bucket used for cloudtrail log storage
cloudtrail_bucket_idThe ID (name) of the bucket used for cloudtrail log storage
catchall_idThe ID of the catchall log archive

References