Skip to content

Commit 721450c

Browse files
Upgraded to 5.x compatibility + refactored S3 bucket for ALB (#8)
* Upgraded to 5.x compatibility + refactored S3 bucket for ALB security logs * Changed the AWS version back to the original minimum version * Update main.tf Co-authored-by: Abdul Wahid <[email protected]> * Update versions.tf Co-authored-by: Abdul Wahid <[email protected]> * Update examples/alb-with-s3-access-logs/versions.tf Co-authored-by: Abdul Wahid <[email protected]> * Update examples/alb/versions.tf Co-authored-by: Abdul Wahid <[email protected]> * Update examples/nlb/versions.tf Co-authored-by: Abdul Wahid <[email protected]> --------- Co-authored-by: Abdul Wahid <[email protected]>
1 parent a0eed4b commit 721450c

File tree

11 files changed

+164
-81
lines changed

11 files changed

+164
-81
lines changed

.pre-commit-config.yaml

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v3.4.0
3+
rev: v4.4.0
44
hooks:
55
- id: check-added-large-files
66
args: ['--maxkb=500']
7-
- id: check-executables-have-shebangs
87
- id: pretty-format-json
98
args: ['--autofix', '--no-sort-keys', '--indent=2']
109
- id: check-byte-order-marker
@@ -17,8 +16,8 @@ repos:
1716
- id: detect-aws-credentials
1817
args: ['--allow-missing-credentials']
1918
- id: trailing-whitespace
20-
- repo: git://github.com/antonbabenko/pre-commit-terraform
21-
rev: v1.50.0
19+
- repo: https://github.com/antonbabenko/pre-commit-terraform
20+
rev: v1.81.0
2221
hooks:
2322
- id: terraform_fmt
2423
- id: terraform_docs

CHANGELOG.md

+24-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
<a name="unreleased"></a>
66
## [Unreleased]
77

8+
- Upgraded to 5.x compatibility + refactored S3 bucket for ALB security logs
9+
10+
11+
<a name="2.1.0"></a>
12+
## [2.1.0] - 2021-05-14
13+
14+
- Add tags to alb listener ([#6](https://github.com/umotif-public/terraform-aws-alb/issues/6))
815
- Update README.md
916

1017

@@ -53,16 +60,31 @@ All notable changes to this project will be documented in this file.
5360

5461

5562
<a name="1.0.2"></a>
56-
## 1.0.2 - 2019-12-12
63+
## [1.0.2] - 2019-12-12
5764

5865
- Add default redirect and nlb example
5966

6067

61-
[Unreleased]: https://github.com/umotif-public/terraform-aws-alb/compare/2.0.0...HEAD
68+
<a name="1.0.1"></a>
69+
## [1.0.1] - 2019-12-11
70+
71+
- add documentation
72+
73+
74+
<a name="1.0.0"></a>
75+
## 1.0.0 - 2019-12-11
76+
77+
- initial module push
78+
79+
80+
[Unreleased]: https://github.com/umotif-public/terraform-aws-alb/compare/2.1.0...HEAD
81+
[2.1.0]: https://github.com/umotif-public/terraform-aws-alb/compare/2.0.0...2.1.0
6282
[2.0.0]: https://github.com/umotif-public/terraform-aws-alb/compare/1.2.2...2.0.0
6383
[1.2.2]: https://github.com/umotif-public/terraform-aws-alb/compare/1.2.1...1.2.2
6484
[1.2.1]: https://github.com/umotif-public/terraform-aws-alb/compare/1.2.0...1.2.1
6585
[1.2.0]: https://github.com/umotif-public/terraform-aws-alb/compare/1.1.0...1.2.0
6686
[1.1.0]: https://github.com/umotif-public/terraform-aws-alb/compare/1.0.4...1.1.0
6787
[1.0.4]: https://github.com/umotif-public/terraform-aws-alb/compare/1.0.3...1.0.4
6888
[1.0.3]: https://github.com/umotif-public/terraform-aws-alb/compare/1.0.2...1.0.3
89+
[1.0.2]: https://github.com/umotif-public/terraform-aws-alb/compare/1.0.1...1.0.2
90+
[1.0.1]: https://github.com/umotif-public/terraform-aws-alb/compare/1.0.0...1.0.1

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,23 @@ module "nlb" {
7272

7373
## Authors
7474

75-
Module managed by [Marcin Cuber](https://github.com/marcincuber) [LinkedIn](https://www.linkedin.com/in/marcincuber/).
75+
## Authors
76+
77+
Module managed by [uMotif](https://github.com/umotif-public/).
7678

7779
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
7880
## Requirements
7981

8082
| Name | Version |
8183
|------|---------|
82-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.12.6 |
83-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.40 |
84+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1.0.11 |
85+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.40.0 |
8486

8587
## Providers
8688

8789
| Name | Version |
8890
|------|---------|
89-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.40 |
91+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.40.0 |
9092

9193
## Modules
9294

+66-54
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
provider "aws" {
2-
region = "eu-west-1"
3-
}
4-
51
#####
62
# VPC and subnets
73
#####
84
data "aws_vpc" "default" {
95
default = true
106
}
117

12-
data "aws_subnet_ids" "all" {
13-
vpc_id = data.aws_vpc.default.id
8+
data "aws_subnets" "all" {
9+
filter {
10+
name = "vpc-id"
11+
values = [data.aws_vpc.default.id]
12+
}
1413
}
14+
1515
#####
1616
# Application Load Balancer
1717
#####
@@ -24,7 +24,7 @@ module "alb" {
2424

2525
internal = false
2626
vpc_id = data.aws_vpc.default.id
27-
subnets = data.aws_subnet_ids.all.ids
27+
subnets = data.aws_subnets.all.ids
2828

2929
enable_http_to_https_redirect = true
3030
cidr_blocks_redirect = ["10.10.0.0/16"]
@@ -76,62 +76,74 @@ resource "aws_security_group_rule" "alb_ingress_443" {
7676
# S3 bucket storing ALB access logs
7777
#####
7878
locals {
79-
alb_root_account_id = "156460612806" # valid account id for Ireland Region. Full list -> https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-access-logs.html
79+
alb_root_account_id = "156460612806" # valid account id for Ireland Region. Full list -> https://docs.aws.amazon.com/elasticloadbalancing/latest/application/enable-access-logging.html
8080
}
8181

8282
resource "aws_s3_bucket" "alb_access_logs" {
8383
bucket = "example-alb-access-logs-bucket"
84-
acl = "private"
8584

86-
server_side_encryption_configuration {
87-
rule {
88-
apply_server_side_encryption_by_default {
89-
sse_algorithm = "AES256"
90-
}
85+
tags = {
86+
Environment = "test"
87+
}
88+
}
89+
90+
resource "aws_s3_bucket_server_side_encryption_configuration" "alb_access_logs_encryption" {
91+
bucket = aws_s3_bucket.alb_access_logs.id
92+
93+
rule {
94+
apply_server_side_encryption_by_default {
95+
sse_algorithm = "AES256"
9196
}
9297
}
98+
}
9399

94-
policy = <<POLICY
95-
{
96-
"Version": "2012-10-17",
97-
"Statement": [
98-
{
99-
"Sid": "AllowELBRootAccount",
100-
"Effect": "Allow",
101-
"Principal": {
102-
"AWS": "arn:aws:iam::${local.alb_root_account_id}:root"
100+
resource "aws_s3_bucket_policy" "alb_access_logs_bucket_policy" {
101+
bucket = aws_s3_bucket.alb_access_logs.id
102+
103+
policy = jsonencode({
104+
"Version" : "2012-10-17",
105+
"Statement" : [
106+
{
107+
"Sid" : "AllowELBRootAccount",
108+
"Effect" : "Allow",
109+
"Action" : "s3:PutObject",
110+
"Resource" : "arn:aws:s3:::example-alb-access-logs-bucket/*",
111+
"Principal" : {
112+
"AWS" : "arn:aws:iam::${local.alb_root_account_id}:root"
113+
}
103114
},
104-
"Action": "s3:PutObject",
105-
"Resource": "arn:aws:s3:::example-alb-access-logs-bucket/*"
106-
},
107-
{
108-
"Sid": "AWSLogDeliveryWrite",
109-
"Effect": "Allow",
110-
"Principal": {
111-
"Service": "delivery.logs.amazonaws.com"
115+
{
116+
"Sid" : "AWSLogDeliveryWrite",
117+
"Effect" : "Allow",
118+
"Action" : "s3:PutObject",
119+
"Resource" : "arn:aws:s3:::example-alb-access-logs-bucket/*",
120+
"Condition" : {
121+
"StringEquals" : {
122+
"s3:x-amz-acl" : "bucket-owner-full-control"
123+
}
124+
},
125+
"Principal" : {
126+
"Service" : "delivery.logs.amazonaws.com"
127+
}
112128
},
113-
"Action": "s3:PutObject",
114-
"Resource": "arn:aws:s3:::example-alb-access-logs-bucket/*",
115-
"Condition": {
116-
"StringEquals": {
117-
"s3:x-amz-acl": "bucket-owner-full-control"
129+
{
130+
"Sid" : "AWSLogDeliveryAclCheck",
131+
"Effect" : "Allow",
132+
"Action" : "s3:GetBucketAcl",
133+
"Resource" : "arn:aws:s3:::example-alb-access-logs-bucket",
134+
"Principal" : {
135+
"Service" : "delivery.logs.amazonaws.com"
118136
}
119-
}
120-
},
121-
{
122-
"Sid": "AWSLogDeliveryAclCheck",
123-
"Effect": "Allow",
124-
"Principal": {
125-
"Service": "delivery.logs.amazonaws.com"
126137
},
127-
"Action": "s3:GetBucketAcl",
128-
"Resource": "arn:aws:s3:::example-alb-access-logs-bucket"
129-
}
130-
]
131-
}
132-
POLICY
133-
134-
tags = {
135-
Environment = "test"
136-
}
137-
}
138+
{
139+
"Sid" : "AllowALBAccess",
140+
"Effect" : "Allow",
141+
"Action" : "s3:PutObject",
142+
"Resource" : "arn:aws:s3:::example-alb-access-logs-bucket/*",
143+
"Principal" : {
144+
"Service" : "elasticloadbalancing.amazonaws.com"
145+
}
146+
}
147+
]
148+
})
149+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
terraform {
2+
required_version = ">= 1.0.11"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = "~> 5"
8+
}
9+
}
10+
}
11+
12+
provider "aws" {
13+
region = "eu-west-1"
14+
}

examples/alb/main.tf

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
provider "aws" {
2-
region = "eu-west-1"
3-
}
4-
51
#####
62
# VPC and subnets
73
#####
84
data "aws_vpc" "default" {
95
default = true
106
}
117

12-
data "aws_subnet_ids" "all" {
13-
vpc_id = data.aws_vpc.default.id
8+
#####
9+
# VPC and subnets
10+
#####
11+
12+
data "aws_subnets" "all" {
13+
filter {
14+
name = "vpc-id"
15+
values = [data.aws_vpc.default.id]
16+
}
1417
}
1518
#####
1619
# Application Load Balancer
@@ -24,7 +27,7 @@ module "alb" {
2427

2528
internal = false
2629
vpc_id = data.aws_vpc.default.id
27-
subnets = data.aws_subnet_ids.all.ids
30+
subnets = data.aws_subnets.all.ids
2831

2932
enable_http_to_https_redirect = true
3033
cidr_blocks_redirect = ["10.10.0.0/16"]

examples/alb/versions.tf

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
terraform {
2+
required_version = ">= 1.0.11"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = "~> 5"
8+
}
9+
}
10+
}
11+
12+
provider "aws" {
13+
region = "eu-west-1"
14+
}

examples/nlb/main.tf

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
provider "aws" {
2-
region = "eu-west-1"
3-
}
4-
51
#####
62
# VPC and subnets
73
#####
84
data "aws_vpc" "default" {
95
default = true
106
}
117

12-
data "aws_subnet_ids" "all" {
13-
vpc_id = data.aws_vpc.default.id
8+
data "aws_subnets" "all" {
9+
filter {
10+
name = "vpc-id"
11+
values = [data.aws_vpc.default.id]
12+
}
1413
}
14+
1515
# resource "aws_eip" "main" {
1616
# count = length(module.vpc.public_subnets)
1717

@@ -29,7 +29,7 @@ module "nlb" {
2929
load_balancer_type = "network"
3030

3131
vpc_id = data.aws_vpc.default.id
32-
subnets = data.aws_subnet_ids.all.ids
32+
subnets = data.aws_subnets.all.ids
3333

3434
// Use `subnet_mapping` to attach EIPs and comment out `subnets`
3535
// subnet_mapping = [for i, eip in aws_eip.main : { allocation_id : eip.id, subnet_id : tolist(module.vpc.public_subnets)[i] }]

examples/nlb/versions.tf

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
terraform {
2+
required_version = ">= 1.0.11"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = "~> 5"
8+
}
9+
}
10+
}
11+
12+
provider "aws" {
13+
region = "eu-west-1"
14+
}

main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ resource "aws_lb" "main" {
44
load_balancer_type = var.load_balancer_type
55
internal = var.internal
66
subnets = var.subnets
7-
security_groups = aws_security_group.main.*.id
7+
security_groups = aws_security_group.main[0].id
88

99
idle_timeout = var.idle_timeout
1010
enable_deletion_protection = var.enable_deletion_protection

versions.tf

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
terraform {
2-
required_version = ">= 0.12.6"
2+
required_version = ">= 1.0.11"
33

44
required_providers {
5-
aws = ">= 3.40"
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 3.40.0"
8+
}
69
}
710
}

0 commit comments

Comments
 (0)