Book Image

Infrastructure as Code (IAC) Cookbook

By : Stephane Jourdan, Pierre Pomès
Book Image

Infrastructure as Code (IAC) Cookbook

By: Stephane Jourdan, Pierre Pomès

Overview of this book

Para 1: Infrastructure as code is transforming the way we solve infrastructural challenges. This book will show you how to make managing servers in the cloud faster, easier and more effective than ever before. With over 90 practical recipes for success, make the very most out of IAC.
Table of Contents (18 chapters)
Infrastructure as Code (IAC) Cookbook
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
Index

Enabling CloudWatch Logs for Docker with Terraform


CloudWatch Logs is a log aggregation service by Amazon you can use to send your logs to. It's very useful to keep some logs centralized, share access to them, receive alarms when errors happen, or simply store them safely. We'll see how to create a CloudWatch Log group and use it to stream logs from a Docker container logs inside it.

Getting ready

To step through this recipe, you will need the following:

  • A working Terraform installation

  • An AWS provider configured in Terraform (refer to the previous recipes)

  • An Internet connection

  • A Docker Engine running on Linux for the optional usage demonstration

How to do it…

Let's say we want the log group to be named docker_logs, and that we want to keep those logs for seven days. In the variables.tf file, that would look like this:

variable "log_group_name" {
  default = "docker_logs"
}

variable "log_retention_days" {
  default = "7"
}

Also, in a new cloudwatch.tf file, we can use the simple aws_cloudwatch_log_group...