-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2c5b802
Showing
5 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "" | ||
} |