Skip to content

cloudposse-terraform-components/aws-datadog-logs-archive

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

65 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Project Banner

Latest ReleaseSlack Community

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 overridable 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

Name Version
terraform >= 0.13.0
aws >= 2.0
datadog >= 3.3.0
local >= 1.3

Providers

Name Version
aws >= 2.0
datadog >= 3.7.0
http >= 2.1.0

Modules

Name Source Version
cloudtrail cloudposse/cloudtrail/aws 0.21.0
cloudtrail_s3_bucket cloudposse/cloudtrail-s3-bucket/aws 0.23.1
iam_roles ../account-map/modules/iam-roles n/a
s3_bucket cloudposse/s3-bucket/aws 0.46.0
this cloudposse/label/null 0.25.0

Resources

Name Type
aws_caller_identity.current data source
aws_partition.current data source
aws_ssm_parameter.datadog_api_key data source
aws_ssm_parameter.datadog_app_key data source
aws_ssm_parameter.datadog_aws_role_name data source
aws_ssm_parameter.datadog_external_id data source
datadog_logs_archive.catchall_archive resource
datadog_logs_archive.logs_archive resource
http.current_order data source

Inputs

Name Description Type Default Required
additional_query_tags Additional tags to include in query for logs for this archive list [] no
catchall Set to true to enable a catchall for logs unmatched by any queries. This should only be used in one environment/account bool false no
datadog_aws_account_id The AWS account ID Datadog's integration servers use for all integrations string 464622532012 no
enable_glacier_transition Enable/disable transition to glacier. Has no effect unless lifecycle_rules_enabled set to true bool true no
glacier_transition_days Number of days after which to transition objects to glacier storage number 365 no
lifecycle_rules_enabled Enable/disable lifecycle management rules for s3 objects bool true no
object_lock_days_archive Set duration of archive bucket object lock number 7 yes
object_lock_days_cloudtrail Set duration of cloudtrail bucket object lock number 7 yes
object_lock_mode_archive Set mode of archive bucket object lock string COMPLIANCE yes
object_lock_mode_cloudtrail Set mode of cloudtrail bucket object lock string COMPLIANCE yes
s3_force_destroy Set to true to delete non-empty buckets when enabled is set to false bool false for destroy only

Outputs

Name Description
archive_id The ID of the environment-specific log archive
bucket_arn The ARN of the bucket used for log archive storage
bucket_domain_name The FQDN of the bucket used for log archive storage
bucket_id The ID (name) of the bucket used for log archive storage
bucket_region The region of the bucket used for log archive storage
cloudtrail_bucket_arn The ARN of the bucket used for cloudtrail log storage
cloudtrail_bucket_domain_name The FQDN of the bucket used for cloudtrail log storage
cloudtrail_bucket_id The ID (name) of the bucket used for cloudtrail log storage
catchall_id The ID of the catchall log archive

References

Tip

πŸ‘½ Use Atmos with Terraform

Cloud Posse uses atmos to easily orchestrate multiple environments using Terraform.
Works with Github Actions, Atlantis, or Spacelift.

Watch demo of using Atmos with Terraform
Example of running atmos to manage infrastructure from our Quick Start tutorial.

Related Projects

Check out these related projects.

  • Cloud Posse Terraform Modules - Our collection of reusable Terraform modules used by our reference architectures.
  • Atmos - Atmos is like docker-compose but for your infrastructure

Tip

Use Terraform Reference Architectures for AWS

Use Cloud Posse's ready-to-go terraform architecture blueprints for AWS to get up and running quickly.

βœ… We build it together with your team.
βœ… Your team owns everything.
βœ… 100% Open Source and backed by fanatical support.

Request Quote

πŸ“š Learn More

Cloud Posse is the leading DevOps Accelerator for funded startups and enterprises.

Your team can operate like a pro today.

Ensure that your team succeeds by using Cloud Posse's proven process and turnkey blueprints. Plus, we stick around until you succeed.

Day-0: Your Foundation for Success

  • Reference Architecture. You'll get everything you need from the ground up built using 100% infrastructure as code.
  • Deployment Strategy. Adopt a proven deployment strategy with GitHub Actions, enabling automated, repeatable, and reliable software releases.
  • Site Reliability Engineering. Gain total visibility into your applications and services with Datadog, ensuring high availability and performance.
  • Security Baseline. Establish a secure environment from the start, with built-in governance, accountability, and comprehensive audit logs, safeguarding your operations.
  • GitOps. Empower your team to manage infrastructure changes confidently and efficiently through Pull Requests, leveraging the full power of GitHub Actions.

Request Quote

Day-2: Your Operational Mastery

  • Training. Equip your team with the knowledge and skills to confidently manage the infrastructure, ensuring long-term success and self-sufficiency.
  • Support. Benefit from a seamless communication over Slack with our experts, ensuring you have the support you need, whenever you need it.
  • Troubleshooting. Access expert assistance to quickly resolve any operational challenges, minimizing downtime and maintaining business continuity.
  • Code Reviews. Enhance your team’s code quality with our expert feedback, fostering continuous improvement and collaboration.
  • Bug Fixes. Rely on our team to troubleshoot and resolve any issues, ensuring your systems run smoothly.
  • Migration Assistance. Accelerate your migration process with our dedicated support, minimizing disruption and speeding up time-to-value.
  • Customer Workshops. Engage with our team in weekly workshops, gaining insights and strategies to continuously improve and innovate.

Request Quote

✨ Contributing

This project is under active development, and we encourage contributions from our community.

Many thanks to our outstanding contributors:

For πŸ› bug reports & feature requests, please use the issue tracker.

In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.

  1. Review our Code of Conduct and Contributor Guidelines.
  2. Fork the repo on GitHub
  3. Clone the project to your own machine
  4. Commit changes to your own branch
  5. Push your work back up to your fork
  6. Submit a Pull Request so that we can review your changes

NOTE: Be sure to merge the latest changes from "upstream" before making a pull request!

🌎 Slack Community

Join our Open Source Community on Slack. It's FREE for everyone! Our "SweetOps" community is where you get to talk with others who share a similar vision for how to rollout and manage infrastructure. This is the best place to talk shop, ask questions, solicit feedback, and work together as a community to build totally sweet infrastructure.

πŸ“° Newsletter

Sign up for our newsletter and join 3,000+ DevOps engineers, CTOs, and founders who get insider access to the latest DevOps trends, so you can always stay in the know. Dropped straight into your Inbox every week β€” and usually a 5-minute read.

πŸ“† Office Hours

Join us every Wednesday via Zoom for your weekly dose of insider DevOps trends, AWS news and Terraform insights, all sourced from our SweetOps community, plus a live Q&A that you can’t find anywhere else. It's FREE for everyone!

License

License

Preamble to the Apache License, Version 2.0

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

  https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.

Trademarks

All other trademarks referenced herein are the property of their respective owners.


Copyright Β© 2017-2025 Cloud Posse, LLC

README footer

Beacon

About

This component is responsible for provisioning Datadog Log Archives

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 15

Languages