Skip to content

Commit 72ec560

Browse files
authored
Bug fixes (#147)
1 parent 618a71b commit 72ec560

File tree

7 files changed

+151
-38
lines changed

7 files changed

+151
-38
lines changed

.github/workflows/auto-readme.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: "auto-readme"
22
on:
3+
workflow_dispatch:
4+
35
schedule:
46
# Example of job definition:
57
# .---------------- minute (0 - 59)
@@ -15,21 +17,35 @@ on:
1517

1618
jobs:
1719
update:
18-
if: github.event_name == 'schedule'
20+
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
1921
runs-on: ubuntu-latest
2022
steps:
2123
- uses: actions/checkout@v2
2224

25+
- name: Find default branch name
26+
id: defaultBranch
27+
shell: bash
28+
env:
29+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
30+
run: |
31+
default_branch=$(gh repo view --json defaultBranchRef --jq .defaultBranchRef.name)
32+
printf "::set-output name=defaultBranch::%s\n" "${default_branch}"
33+
printf "defaultBranchRef.name=%s\n" "${default_branch}"
34+
2335
- name: Update readme
2436
shell: bash
2537
id: update
2638
env:
2739
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
40+
DEF: "${{ steps.defaultBranch.outputs.defaultBranch }}"
2841
run: |
2942
make init
3043
make readme/build
3144
# Ignore changes if they are only whitespace
32-
git diff --ignore-all-space --ignore-blank-lines --quiet README.md && { git restore README.md; echo Ignoring whitespace-only changes in README; }
45+
if ! git diff --quiet README.md && git diff --ignore-all-space --ignore-blank-lines --quiet README.md; then
46+
git restore README.md
47+
echo Ignoring whitespace-only changes in README
48+
fi
3349
3450
- name: Create Pull Request
3551
# This action will not create or change a pull request if there are no changes to make.
@@ -47,7 +63,7 @@ jobs:
4763
To have most recent changes of README.md and doc from origin templates
4864
4965
branch: auto-update/readme
50-
base: main
66+
base: ${{ steps.defaultBranch.outputs.defaultBranch }}
5167
delete-branch: true
5268
labels: |
5369
auto-update

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,14 @@ Available targets:
254254
| Name | Version |
255255
|------|---------|
256256
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
257-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.2.0 |
257+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.9.0 |
258258
| <a name="requirement_time"></a> [time](#requirement\_time) | >= 0.7 |
259259

260260
## Providers
261261

262262
| Name | Version |
263263
|------|---------|
264-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.2.0 |
264+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.9.0 |
265265
| <a name="provider_time"></a> [time](#provider\_time) | >= 0.7 |
266266

267267
## Modules

docs/terraform.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
| Name | Version |
55
|------|---------|
66
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
7-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.2.0 |
7+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.9.0 |
88
| <a name="requirement_time"></a> [time](#requirement\_time) | >= 0.7 |
99

1010
## Providers
1111

1212
| Name | Version |
1313
|------|---------|
14-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.2.0 |
14+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.9.0 |
1515
| <a name="provider_time"></a> [time](#provider\_time) | >= 0.7 |
1616

1717
## Modules

examples/complete/lifecycle.us-east-2.tfvars

Lines changed: 91 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,105 @@ name = "s3-lifecycle-test"
99
acl = "private"
1010

1111
lifecycle_configuration_rules = [
12+
# Be sure to cover https://github.com/cloudposse/terraform-aws-s3-bucket/issues/137
1213
{
13-
enabled = true # bool
14-
id = "v2rule"
14+
abort_incomplete_multipart_upload_days = 1
15+
enabled = true
16+
expiration = {
17+
days = null
18+
expired_object_delete_marker = null
19+
}
20+
21+
# test no filter
22+
filter_and = {}
23+
id = "nofilter"
24+
noncurrent_version_expiration = {
25+
newer_noncurrent_versions = 2
26+
noncurrent_days = 30
27+
}
28+
noncurrent_version_transition = []
29+
transition = [
30+
{
31+
days = 7
32+
storage_class = "GLACIER"
33+
},
34+
]
1535

16-
abort_incomplete_multipart_upload_days = 1 # number
36+
},
37+
{
38+
abort_incomplete_multipart_upload_days = 1
39+
enabled = true
40+
expiration = {
41+
days = null
42+
expired_object_delete_marker = null
43+
}
44+
45+
# test prefix only
46+
filter_and = {
47+
prefix = "prefix1"
48+
}
49+
id = "prefix1"
50+
noncurrent_version_expiration = {
51+
newer_noncurrent_versions = 2
52+
noncurrent_days = 30
53+
}
54+
noncurrent_version_transition = []
55+
transition = [
56+
{
57+
days = 7
58+
storage_class = "GLACIER"
59+
},
60+
]
1761

18-
filter_and = null
62+
},
63+
{
64+
abort_incomplete_multipart_upload_days = null
65+
enabled = true
1966
expiration = {
20-
days = 120 # integer > 0
67+
days = 1461
68+
expired_object_delete_marker = false
2169
}
70+
# test prefix with other filter
71+
filter_and = {
72+
prefix = "prefix2"
73+
object_size_greater_than = 128 * 1024
74+
}
75+
id = "prefix2"
2276
noncurrent_version_expiration = {
23-
newer_noncurrent_versions = 3 # integer > 0
24-
noncurrent_days = 60 # integer >= 0
77+
newer_noncurrent_versions = 2
78+
noncurrent_days = 14
2579
}
26-
transition = [{
27-
days = 30 # integer >= 0
28-
storage_class = "STANDARD_IA" # string/enum, one of GLACIER, STANDARD_IA, ONEZONE_IA, INTELLIGENT_TIERING, DEEP_ARCHIVE, GLACIER_IR.
80+
noncurrent_version_transition = []
81+
transition = [
82+
{
83+
days = 366
84+
storage_class = "GLACIER"
2985
},
86+
]
87+
},
88+
{
89+
abort_incomplete_multipart_upload_days = null
90+
enabled = true
91+
expiration = {
92+
days = 93
93+
expired_object_delete_marker = false
94+
}
95+
# test filter without prefix
96+
filter_and = {
97+
object_size_greater_than = 256 * 1024
98+
}
99+
id = "big"
100+
noncurrent_version_expiration = {
101+
newer_noncurrent_versions = 2
102+
noncurrent_days = 14
103+
}
104+
noncurrent_version_transition = []
105+
transition = [
30106
{
31-
days = 60 # integer >= 0
32-
storage_class = "ONEZONE_IA" # string/enum, one of GLACIER, STANDARD_IA, ONEZONE_IA, INTELLIGENT_TIERING, DEEP_ARCHIVE, GLACIER_IR.
33-
}]
34-
noncurrent_version_transition = [{
35-
newer_noncurrent_versions = 3 # integer >= 0
36-
noncurrent_days = 30 # integer >= 0
37-
storage_class = "ONEZONE_IA" # string/enum, one of GLACIER, STANDARD_IA, ONEZONE_IA, INTELLIGENT_TIERING, DEEP_ARCHIVE, GLACIER_IR.
38-
}]
107+
days = 90
108+
storage_class = "GLACIER"
109+
},
110+
]
39111
}
40112
]
41113

@@ -84,6 +156,7 @@ lifecycle_rules = [
84156
}
85157
]
86158

159+
87160
force_destroy = true
88161

89162
versioning_enabled = false

lifecycle.tf

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ locals {
55
id = null # string, must be specified and unique
66

77
abort_incomplete_multipart_upload_days = null # number
8+
filter_prefix_only = null # string See https://github.com/hashicorp/terraform-provider-aws/issues/23882
89
filter_and = {
910
object_size_greater_than = null # integer >= 0
1011
object_size_less_than = null # integer >= 1
@@ -39,9 +40,16 @@ locals {
3940
id = rule.id
4041

4142
abort_incomplete_multipart_upload_days = rule.abort_incomplete_multipart_upload_days # number
43+
44+
# Due to https://github.com/hashicorp/terraform-provider-aws/issues/23882
45+
# we have to treat having only the `prefix` set differently than having any other setting.
46+
filter_prefix_only = (try(rule.filter_and.object_size_greater_than, null) == null &&
47+
try(rule.filter_and.object_size_less_than, null) == null &&
48+
try(length(rule.filter_and.tags), 0) == 0 &&
49+
try(length(rule.filter_and.prefix), 0) > 0) ? rule.filter_and.prefix : null
50+
4251
filter_and = (try(rule.filter_and.object_size_greater_than, null) == null &&
4352
try(rule.filter_and.object_size_less_than, null) == null &&
44-
try(length(rule.filter_and.prefix), 0) == 0 &&
4553
try(length(rule.filter_and.tags), 0) == 0) ? null : {
4654
object_size_greater_than = try(rule.filter_and.object_size_greater_than, null)
4755
object_size_less_than = try(rule.filter_and.object_size_less_than, null)
@@ -84,7 +92,9 @@ locals {
8492
id = try(var.lifecycle_rule_ids[i], "rule-${i + 1}")
8593

8694
abort_incomplete_multipart_upload_days = rule.abort_incomplete_multipart_upload_days # number
87-
filter_and = try(length(rule.prefix), 0) == 0 && try(length(rule.tags), 0) == 0 ? null : {
95+
96+
filter_prefix_only = try(length(rule.prefix), 0) > 0 && try(length(rule.tags), 0) == 0 ? rule.prefix : null
97+
filter_and = try(length(rule.tags), 0) == 0 ? null : {
8898
object_size_greater_than = null # integer >= 0
8999
object_size_less_than = null # integer >= 1
90100
prefix = rule.prefix == "" ? null : rule.prefix # string
@@ -133,7 +143,7 @@ locals {
133143
# enabled the transition for both current and non-current version.
134144
rule.enable_deeparchive_transition != true ? [] :
135145
[{
136-
newer_noncurrent_versions = null # string
146+
newer_noncurrent_versions = null # integer >= 0
137147
noncurrent_days = rule.noncurrent_version_deeparchive_transition_days # integer >= 0
138148
storage_class = "DEEP_ARCHIVE"
139149
}],
@@ -156,14 +166,28 @@ resource "aws_s3_bucket_lifecycle_configuration" "default" {
156166
status = rule.value.enabled == true ? "Enabled" : "Disabled"
157167

158168
# Filter is always required due to https://github.com/hashicorp/terraform-provider-aws/issues/23299
159-
filter {
160-
dynamic "and" {
161-
for_each = rule.value.filter_and == null ? [] : [rule.value.filter_and]
162-
content {
163-
object_size_greater_than = and.value.object_size_greater_than
164-
object_size_less_than = and.value.object_size_less_than
165-
prefix = and.value.prefix
166-
tags = and.value.tags
169+
dynamic "filter" {
170+
for_each = rule.value.filter_prefix_only == null && rule.value.filter_and == null ? ["empty"] : []
171+
content {}
172+
}
173+
174+
# When only specifying `prefix`, do not use `and` due to https://github.com/hashicorp/terraform-provider-aws/issues/23882
175+
dynamic "filter" {
176+
for_each = rule.value.filter_prefix_only == null ? [] : ["prefix"]
177+
content {
178+
prefix = rule.value.filter_prefix_only
179+
}
180+
}
181+
182+
# When specifying more than 1 filter criterion, use `and`
183+
dynamic "filter" {
184+
for_each = rule.value.filter_and == null ? [] : ["and"]
185+
content {
186+
and {
187+
object_size_greater_than = rule.value.filter_and.object_size_greater_than
188+
object_size_less_than = rule.value.filter_and.object_size_less_than
189+
prefix = rule.value.filter_and.prefix
190+
tags = rule.value.filter_and.tags
167191
}
168192
}
169193
}

main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ data "aws_iam_policy_document" "aggregated_policy" {
444444
}
445445

446446
resource "aws_s3_bucket_policy" "default" {
447-
count = local.enabled && (var.allow_ssl_requests_only || var.allow_encrypted_uploads_only || length(var.s3_replication_source_roles) > 0 || length(var.privileged_principal_arns) > 0 || var.policy != "") ? 1 : 0
447+
count = local.enabled && (var.allow_ssl_requests_only || var.allow_encrypted_uploads_only || length(var.s3_replication_source_roles) > 0 || length(var.privileged_principal_arns) > 0 || length(var.source_policy_documents) > 0) ? 1 : 0
448448
bucket = join("", aws_s3_bucket.default.*.id)
449449
policy = join("", data.aws_iam_policy_document.aggregated_policy.*.json)
450450
depends_on = [aws_s3_bucket_public_access_block.default]

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 4.2.0"
7+
version = ">= 4.9.0"
88
}
99
time = {
1010
source = "hashicorp/time"

0 commit comments

Comments
 (0)