Skip to content

Commit 5bc98cb

Browse files
feat!: enable support for aws provider 4.0+ (#49)
BREAKING CHANGE: This release drops support for AWS provider <4.0 When updating to this version, the diff will show each of the new resources as needing to be created. However, each of the new aws_s3_bucket_* resources relies on S3 API calls that utilize a PUT action in order to modify the target S3 bucket. Because these API calls adhere to standard HTTP methods for REST APIs, they should handle situations where the target configuration already exists (as noted in the HTTP RFC). Given that this is the case, it's not strictly necessary to import any new aws_s3_bucket_* resources that are a one-to-one translation from previous versions of the AWS provider -- on the next terraform apply, they'll attempt the PUT, and update the state with the results as necessary.
1 parent 117aaf2 commit 5bc98cb

File tree

3 files changed

+47
-36
lines changed

3 files changed

+47
-36
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Cloudwatch log sync are namspaced by module.
7272

7373
## Module Versions
7474

75+
**Version 3.x.x** and greater require terraform version > 0.13.x and AWS provider > 4.0.0.
7576
**Version 2.x.x** and greater require terraform version > 0.13.x and AWS provider < 4.0.0.
7677
**Version 1.x.x** is the latest version that support terraform version 0.12.x and AWS provider < 4.0.0.
7778
When using this module, please be sure to [pin to a compatible version](https://www.terraform.io/docs/configuration/modules.html#module-versions).

logs_monitoring_elb.tf

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,48 +25,46 @@ locals {
2525
elb_logs_s3_bucket = "${var.elb_logs_bucket_prefix}-${var.namespace}-${var.env}-elb-logs"
2626
}
2727

28+
data aws_iam_policy_document "elb_logs" {
29+
statement {
30+
actions = [
31+
"s3:PutObject"
32+
]
33+
resources = [
34+
"arn:aws:s3:::${local.elb_logs_s3_bucket}/*",
35+
]
36+
principals {
37+
type = "AWS"
38+
identifiers = [data.aws_elb_service_account.main.arn]
39+
}
40+
effect = "Allow"
41+
}
42+
}
43+
2844
resource "aws_s3_bucket" "elb_logs" {
2945
count = var.create_elb_logs_bucket ? 1 : 0
3046
bucket = local.elb_logs_s3_bucket
31-
acl = "private"
32-
policy = <<POLICY
33-
{
34-
"Id": "Policy",
35-
"Version": "2012-10-17",
36-
"Statement": [
37-
{
38-
"Action": [
39-
"s3:PutObject"
40-
],
41-
"Effect": "Allow",
42-
"Resource": "arn:aws:s3:::${local.elb_logs_s3_bucket}/*",
43-
"Principal": {
44-
"AWS": [
45-
"${data.aws_elb_service_account.main.arn}"
46-
]
47-
}
48-
}
49-
]
5047
}
51-
POLICY
5248

53-
server_side_encryption_configuration {
54-
rule {
55-
apply_server_side_encryption_by_default {
56-
sse_algorithm = "AES256"
57-
}
58-
}
59-
}
49+
resource "aws_s3_bucket_policy" "elb_logs" {
50+
count = var.create_elb_logs_bucket ? 1 : 0
51+
bucket = aws_s3_bucket.elb_logs[0].id
52+
policy = data.aws_iam_policy_document.elb_logs.json
53+
}
6054

61-
lifecycle_rule {
62-
id = "log"
63-
enabled = true
55+
resource "aws_s3_bucket_acl" "elb_logs" {
56+
count = var.create_elb_logs_bucket ? 1 : 0
57+
bucket = aws_s3_bucket.elb_logs[0].id
58+
acl = "private"
59+
}
6460

65-
tags = {
66-
"rule" = "log"
67-
"autoclean" = "true"
68-
}
61+
resource "aws_s3_bucket_lifecycle_configuration" "elb_logs" {
62+
count = var.create_elb_logs_bucket ? 1 : 0
63+
bucket = aws_s3_bucket.elb_logs[0].id
6964

65+
# Remove old versions of images after 15 days
66+
rule {
67+
id = "log"
7068
transition {
7169
days = 30
7270
storage_class = "STANDARD_IA" # or "ONEZONE_IA"
@@ -80,5 +78,17 @@ POLICY
8078
expiration {
8179
days = 365 # store logs for one year
8280
}
81+
status = "Enabled"
82+
}
83+
}
84+
85+
resource "aws_s3_bucket_server_side_encryption_configuration" "elb_logs" {
86+
count = var.create_elb_logs_bucket ? 1 : 0
87+
bucket = aws_s3_bucket.elb_logs[0].id
88+
89+
rule {
90+
apply_server_side_encryption_by_default {
91+
sse_algorithm = "AES256"
92+
}
8393
}
8494
}

versions.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ terraform {
88
}
99

1010
aws = {
11-
source = "hashicorp/aws"
12-
version = ">= 3.0, < 4"
11+
source = "hashicorp/aws"
12+
version = ">= 4.0"
1313
}
1414
}
1515
}

0 commit comments

Comments
 (0)