Skip to content

Commit

Permalink
chore(files): Upload
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricios committed Jul 28, 2018
0 parents commit 2c5b802
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Aplyca

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Terraform AWS CloudWatch Logs module
====================================

Create a AWS CloudWatch Logs resources
61 changes: 61 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
locals {
id = "${replace(var.name, " ", "-")}"
}

resource "aws_cloudwatch_log_group" "this" {
name = "${local.id}"
retention_in_days = "${var.retention_in_days}"
tags = "${var.tags}"
}

resource "aws_cloudwatch_log_stream" "this" {
count = "${length(var.streams)}"
name = "${element(var.streams, count.index)}"
log_group_name = "${aws_cloudwatch_log_group.this.name}"
}

data "aws_iam_policy_document" "this" {
statement {
actions = [
"logs:DescribeLogGroups",
"logs:DescribeLogStreams",
]

resources = ["*"]
}

statement {
actions = [
"logs:PutLogEvents",
]

resources = [
"${aws_cloudwatch_log_group.this.arn}",
]
}

statement {
actions = [
"${var.additional_permissions}",
]

resources = [
"${aws_cloudwatch_log_group.this.arn}",
]
}
}

resource "aws_iam_policy" "this" {
name = "${local.id}-CloudWatchLogs"
description = "${var.description}"
policy = "${data.aws_iam_policy_document.this.json}"
}

# --------------------------------------------------------
# CREATE IAM Policy attachment
# --------------------------------------------------------
resource "aws_iam_role_policy_attachment" "this" {
count = "${var.role != "" ? 1 : 0}"
role = "${var.role}"
policy_arn = "${aws_iam_policy.this.arn}"
}
9 changes: 9 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "name" {
description = "Name of log group"
value = "${aws_cloudwatch_log_group.this.name}"
}

output "policy_arn" {
value = "${aws_iam_policy.this.arn}"
description = "ARN of policy of CloudWatch log"
}
40 changes: 40 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
variable "name" {
description = "Name prefix for all CloudWatch Logs resources"
default = "App"
}

variable "retention_in_days" {
description = "Number of days you want to retain log events in the log group"
default = 0
}

variable "streams" {
description = "Group log streams names"
default = []
}

variable "tags" {
type = "map"
default = {}
description = "Additional tags (e.g. map('BusinessUnit`,`XYZ`)"
}

variable "additional_permissions" {
default = [
"logs:CreateLogStream",
"logs:DeleteLogStream",
]

type = "list"
description = "Additional permissions granted to assumed role"
}

variable "description" {
description = "Description of policy"
default = ""
}

variable "role" {
description = "Role name"
default = ""
}

0 comments on commit 2c5b802

Please sign in to comment.