Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: enable support for aws provider 4.0+ #49

Merged
merged 1 commit into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Cloudwatch log sync are namspaced by module.

## Module Versions

**Version 3.x.x** and greater require terraform version > 0.13.x and AWS provider > 4.0.0.
**Version 2.x.x** and greater require terraform version > 0.13.x and AWS provider < 4.0.0.
**Version 1.x.x** is the latest version that support terraform version 0.12.x and AWS provider < 4.0.0.
When using this module, please be sure to [pin to a compatible version](https://www.terraform.io/docs/configuration/modules.html#module-versions).
Expand Down
78 changes: 44 additions & 34 deletions logs_monitoring_elb.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,48 +25,46 @@ locals {
elb_logs_s3_bucket = "${var.elb_logs_bucket_prefix}-${var.namespace}-${var.env}-elb-logs"
}

data aws_iam_policy_document "elb_logs" {
statement {
actions = [
"s3:PutObject"
]
resources = [
"arn:aws:s3:::${local.elb_logs_s3_bucket}/*",
]
principals {
type = "AWS"
identifiers = [data.aws_elb_service_account.main.arn]
}
effect = "Allow"
}
}

resource "aws_s3_bucket" "elb_logs" {
count = var.create_elb_logs_bucket ? 1 : 0
bucket = local.elb_logs_s3_bucket
acl = "private"
policy = <<POLICY
{
"Id": "Policy",
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:PutObject"
],
"Effect": "Allow",
"Resource": "arn:aws:s3:::${local.elb_logs_s3_bucket}/*",
"Principal": {
"AWS": [
"${data.aws_elb_service_account.main.arn}"
]
}
}
]
}
POLICY

server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
resource "aws_s3_bucket_policy" "elb_logs" {
count = var.create_elb_logs_bucket ? 1 : 0
bucket = aws_s3_bucket.elb_logs[0].id
policy = data.aws_iam_policy_document.elb_logs.json
}

lifecycle_rule {
id = "log"
enabled = true
resource "aws_s3_bucket_acl" "elb_logs" {
count = var.create_elb_logs_bucket ? 1 : 0
bucket = aws_s3_bucket.elb_logs[0].id
acl = "private"
}

tags = {
"rule" = "log"
"autoclean" = "true"
}
resource "aws_s3_bucket_lifecycle_configuration" "elb_logs" {
count = var.create_elb_logs_bucket ? 1 : 0
bucket = aws_s3_bucket.elb_logs[0].id

# Remove old versions of images after 15 days
rule {
id = "log"
transition {
days = 30
storage_class = "STANDARD_IA" # or "ONEZONE_IA"
Expand All @@ -80,5 +78,17 @@ POLICY
expiration {
days = 365 # store logs for one year
}
status = "Enabled"
}
}

resource "aws_s3_bucket_server_side_encryption_configuration" "elb_logs" {
count = var.create_elb_logs_bucket ? 1 : 0
bucket = aws_s3_bucket.elb_logs[0].id

rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
4 changes: 2 additions & 2 deletions versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ terraform {
}

aws = {
source = "hashicorp/aws"
version = ">= 3.0, < 4"
source = "hashicorp/aws"
version = ">= 4.0"
}
}
}