Skip to content

Commit b87a8be

Browse files
max-loburmilldrgithub-actions[bot]
authored
Support AWS Provider V5 (#284)
* Support AWS Provider V5 * Update versions.tf * Update versions.tf * Update versions.tf * Support AWS Provider V5 * bump provider * Support AWS Provider V5 * Support AWS Provider V5 * Support AWS Provider V5 * Support AWS Provider V5 * upd * upd * upd * upd * upd * upd * upd * upd * upd * upd * upd * upd * upd * Add policy * use ACL for logging s3-bucket access * make readme * Removed unused locals, use updated bucket acl pattern, enable logging by local * allow public policy for test bucket * tf fmt * set BucketOwnerEnforced * set acl with string, not grant * set logs ownership to ObjectWriter * set s3_object_ownership for test buckets * set logs bucket to BucketOwnerPreferred * Set bucket-owner-full-control * reset to grant * Update main.tf Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * set log-delivery-write for test bucekts * set ownership on test bucket * set BucketOwnerPreferred with grant list for test buckets * reset tests, set ownership to BucketOwnerPreferred * setting s3_object_ownership * dependency for bucket settings before cdn * Update examples/complete/main.tf Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * dependency for tweaks * added more wait ons for bucket settings * added more wait ons for bucket settings * set ownership on test bucket, set acl null of s3 * set BucketOwnerEnforced * set grants * set grants * Set policy after bucket settings * Set block_origin_public_access_enabled * revert s3-origins test * set BucketOwnerEnforced * sleep for eventual consistency * Set acl for s3-origin tests * replace s3-website module with s3-bucket for tests * corrected bucket name input * corrected bucket name input * bridgecrew issues resolved --------- Co-authored-by: milldr <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 8bab65c commit b87a8be

File tree

17 files changed

+1040
-454
lines changed

17 files changed

+1040
-454
lines changed

.github/workflows/release-branch.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
- 'docs/**'
1111
- 'examples/**'
1212
- 'test/**'
13+
- 'README.*'
1314

1415
permissions:
1516
contents: write

.github/workflows/release-published.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ permissions:
1111

1212
jobs:
1313
terraform-module:
14-
uses: cloudposse/github-actions-workflows-terraform-module/.github/workflows/release.yml@main
14+
uses: cloudposse/github-actions-workflows-terraform-module/.github/workflows/release-published.yml@main

README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@ We highly recommend that in your code you pin the version to the exact version y
8888
using so that your infrastructure remains stable, and update versions in a
8989
systematic way so that they do not catch you by surprise.
9090

91-
Also, because of a bug in the Terraform registry ([hashicorp/terraform#21417](https://github.com/hashicorp/terraform/issues/21417)),
92-
the registry shows many of our inputs as required when in fact they are optional.
93-
The table below correctly indicates which inputs are required.
94-
9591

9692

9793
For a complete example, see [examples/complete](examples/complete).
@@ -387,7 +383,7 @@ module "lambda_at_edge" {
387383
EOT
388384
filename = "index.js"
389385
}]
390-
runtime = "nodejs12.x"
386+
runtime = "nodejs16.x"
391387
handler = "index.handler"
392388
event_type = "origin-response"
393389
include_body = false
@@ -436,15 +432,15 @@ Available targets:
436432
| Name | Version |
437433
|------|---------|
438434
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
439-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.64.0, != 4.0.0, != 4.1.0, != 4.2.0, != 4.3.0, != 4.4.0, != 4.5.0, != 4.6.0, != 4.7.0, != 4.8.0 |
435+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.9 |
440436
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.2 |
441437
| <a name="requirement_time"></a> [time](#requirement\_time) | >= 0.7 |
442438

443439
## Providers
444440

445441
| Name | Version |
446442
|------|---------|
447-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.64.0, != 4.0.0, != 4.1.0, != 4.2.0, != 4.3.0, != 4.4.0, != 4.5.0, != 4.6.0, != 4.7.0, != 4.8.0 |
443+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.9 |
448444
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.2 |
449445
| <a name="provider_time"></a> [time](#provider\_time) | >= 0.7 |
450446

@@ -453,7 +449,7 @@ Available targets:
453449
| Name | Source | Version |
454450
|------|--------|---------|
455451
| <a name="module_dns"></a> [dns](#module\_dns) | cloudposse/route53-alias/aws | 0.13.0 |
456-
| <a name="module_logs"></a> [logs](#module\_logs) | cloudposse/s3-log-storage/aws | 0.26.0 |
452+
| <a name="module_logs"></a> [logs](#module\_logs) | cloudposse/s3-log-storage/aws | 1.4.2 |
457453
| <a name="module_origin_label"></a> [origin\_label](#module\_origin\_label) | cloudposse/label/null | 0.25.0 |
458454
| <a name="module_this"></a> [this](#module\_this) | cloudposse/label/null | 0.25.0 |
459455

README.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ usage: |-
352352
EOT
353353
filename = "index.js"
354354
}]
355-
runtime = "nodejs12.x"
355+
runtime = "nodejs16.x"
356356
handler = "index.handler"
357357
event_type = "origin-response"
358358
include_body = false

docs/terraform.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
| Name | Version |
55
|------|---------|
66
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
7-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.64.0, != 4.0.0, != 4.1.0, != 4.2.0, != 4.3.0, != 4.4.0, != 4.5.0, != 4.6.0, != 4.7.0, != 4.8.0 |
7+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.9 |
88
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.2 |
99
| <a name="requirement_time"></a> [time](#requirement\_time) | >= 0.7 |
1010

1111
## Providers
1212

1313
| Name | Version |
1414
|------|---------|
15-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.64.0, != 4.0.0, != 4.1.0, != 4.2.0, != 4.3.0, != 4.4.0, != 4.5.0, != 4.6.0, != 4.7.0, != 4.8.0 |
15+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.9 |
1616
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.2 |
1717
| <a name="provider_time"></a> [time](#provider\_time) | >= 0.7 |
1818

@@ -21,7 +21,7 @@
2121
| Name | Source | Version |
2222
|------|--------|---------|
2323
| <a name="module_dns"></a> [dns](#module\_dns) | cloudposse/route53-alias/aws | 0.13.0 |
24-
| <a name="module_logs"></a> [logs](#module\_logs) | cloudposse/s3-log-storage/aws | 0.26.0 |
24+
| <a name="module_logs"></a> [logs](#module\_logs) | cloudposse/s3-log-storage/aws | 1.4.2 |
2525
| <a name="module_origin_label"></a> [origin\_label](#module\_origin\_label) | cloudposse/label/null | 0.25.0 |
2626
| <a name="module_this"></a> [this](#module\_this) | cloudposse/label/null | 0.25.0 |
2727

examples/complete/custom-origins.tf

Lines changed: 85 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,37 @@ locals {
1616
}
1717
additional_custom_origin_primary = local.additional_custom_origins_enabled ? merge(
1818
local.default_custom_origin_configuration, {
19-
domain_name = module.additional_custom_origin.s3_bucket_website_endpoint
20-
origin_id = module.additional_custom_origin.hostname
19+
domain_name = module.additional_custom_origin.bucket_website_endpoint
20+
origin_id = module.additional_custom_origin.bucket_id
2121
}
2222
) : null
2323
additional_custom_origin_secondary = local.additional_custom_origins_enabled ? merge(
2424
local.default_custom_origin_configuration, {
25-
domain_name = module.additional_custom_failover_origin.s3_bucket_website_endpoint
26-
origin_id = module.additional_custom_failover_origin.hostname
25+
domain_name = module.additional_custom_failover_origin.bucket_website_endpoint
26+
origin_id = module.additional_custom_failover_origin.bucket_id
2727
}
2828
) : null
2929
additional_custom_origin_groups = local.additional_custom_origins_enabled ? [{
3030
primary_origin_id = local.additional_custom_origin_primary.origin_id
3131
failover_origin_id = local.additional_custom_origin_secondary.origin_id
3232
failover_criteria = var.origin_group_failover_criteria_status_codes
3333
}] : []
34+
website_configuration = [
35+
{
36+
index_document = "index.html"
37+
error_document = null
38+
routing_rules = []
39+
}
40+
]
41+
cors_configuration = [
42+
{
43+
allowed_headers = ["*"]
44+
allowed_methods = ["GET"]
45+
allowed_origins = ["*"]
46+
expose_headers = ["ETag"]
47+
max_age_seconds = 3600
48+
}
49+
]
3450
}
3551

3652
# additional labels are required because they will be used for the 'hostname' variables for each of the additional website origins.
@@ -45,16 +61,44 @@ module "additional_custom_origin_label" {
4561
}
4662

4763
module "additional_custom_origin" {
48-
source = "cloudposse/s3-website/aws"
49-
version = "0.16.1"
64+
source = "cloudposse/s3-bucket/aws"
65+
version = "3.1.2"
66+
5067
enabled = local.additional_custom_origins_enabled
5168

52-
force_destroy = true
53-
hostname = format("%s.%s", module.additional_custom_origin_label.id, var.parent_zone_name)
69+
bucket_name = format("%s.%s", module.additional_custom_origin_label.id, var.parent_zone_name)
70+
force_destroy = true
71+
website_configuration = local.website_configuration
72+
cors_configuration = local.cors_configuration
5473

5574
context = module.additional_custom_origin_label.context
5675
}
5776

77+
resource "aws_s3_bucket_public_access_block" "additional_custom_origin" {
78+
count = local.additional_custom_origins_enabled ? 1 : 0
79+
80+
# The bucket used for a public static website.
81+
#bridgecrew:skip=BC_AWS_S3_19:Skipping `Ensure S3 bucket has block public ACLS enabled`
82+
#bridgecrew:skip=BC_AWS_S3_20:Skipping `Ensure S3 Bucket BlockPublicPolicy is set to True`
83+
#bridgecrew:skip=BC_AWS_S3_21:Skipping `Ensure S3 bucket IgnorePublicAcls is set to True`
84+
#bridgecrew:skip=BC_AWS_S3_22:Skipping `Ensure S3 bucket RestrictPublicBucket is set to True`
85+
bucket = module.additional_custom_origin.bucket_id
86+
87+
block_public_acls = false
88+
block_public_policy = false
89+
ignore_public_acls = false
90+
restrict_public_buckets = false
91+
}
92+
93+
resource "aws_s3_bucket_ownership_controls" "additional_custom_origin" {
94+
count = local.additional_custom_origins_enabled ? 1 : 0
95+
96+
bucket = module.additional_custom_origin.bucket_id
97+
rule {
98+
object_ownership = "BucketOwnerEnforced"
99+
}
100+
}
101+
58102
module "additional_custom_failover_origin_label" {
59103
source = "cloudposse/label/null"
60104
version = "0.24.1"
@@ -66,12 +110,41 @@ module "additional_custom_failover_origin_label" {
66110
}
67111

68112
module "additional_custom_failover_origin" {
69-
source = "cloudposse/s3-website/aws"
70-
version = "0.16.1"
113+
source = "cloudposse/s3-bucket/aws"
114+
version = "3.1.2"
115+
71116
enabled = local.additional_custom_origins_enabled
72117

73-
force_destroy = true
74-
hostname = format("%s.%s", module.additional_custom_failover_origin_label.id, var.parent_zone_name)
118+
bucket_name = format("%s.%s", module.additional_custom_failover_origin_label.id, var.parent_zone_name)
119+
force_destroy = true
120+
website_configuration = local.website_configuration
121+
cors_configuration = local.cors_configuration
75122

76123
context = module.additional_custom_failover_origin_label.context
77124
}
125+
126+
resource "aws_s3_bucket_public_access_block" "additional_custom_failover_origin" {
127+
count = local.additional_custom_origins_enabled ? 1 : 0
128+
129+
# The bucket used for a public static website.
130+
#bridgecrew:skip=BC_AWS_S3_19:Skipping `Ensure S3 bucket has block public ACLS enabled`
131+
#bridgecrew:skip=BC_AWS_S3_20:Skipping `Ensure S3 Bucket BlockPublicPolicy is set to True`
132+
#bridgecrew:skip=BC_AWS_S3_21:Skipping `Ensure S3 bucket IgnorePublicAcls is set to True`
133+
#bridgecrew:skip=BC_AWS_S3_22:Skipping `Ensure S3 bucket RestrictPublicBucket is set to True`
134+
bucket = module.additional_custom_failover_origin.bucket_id
135+
136+
block_public_acls = false
137+
block_public_policy = false
138+
ignore_public_acls = false
139+
restrict_public_buckets = false
140+
}
141+
142+
resource "aws_s3_bucket_ownership_controls" "additional_custom_failover_origin" {
143+
count = local.additional_custom_origins_enabled ? 1 : 0
144+
145+
bucket = module.additional_custom_failover_origin.bucket_id
146+
rule {
147+
object_ownership = "BucketOwnerEnforced"
148+
}
149+
}
150+

examples/complete/deployment.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ locals {
77
} : {}
88

99
our_account_id = local.enabled ? data.aws_caller_identity.current[0].account_id : ""
10-
our_role_arn_prefix = "arn:${join("", data.aws_partition.current.*.partition)}:iam::${local.our_account_id}:role"
10+
our_role_arn_prefix = "arn:${join("", data.aws_partition.current[*].partition)}:iam::${local.our_account_id}:role"
1111
role_names = { for k, v in local.test_deployment_role_prefix_map : k => module.role_labels[k].id }
1212
deployment_principal_arns = { for k, v in local.role_names : format("%v/%v", local.our_role_arn_prefix, v) => local.test_deployment_role_prefix_map[k] }
1313
}

examples/complete/lambda-at-edge.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,22 @@ module "lambda_at_edge" {
3030
EOT
3131
filename = "index.js"
3232
}]
33-
runtime = "nodejs12.x"
33+
runtime = "nodejs16.x"
3434
handler = "index.handler"
3535
event_type = "viewer-request"
3636
include_body = false
3737
},
3838
# Add custom header to the response
3939
viewer_response = {
4040
source_dir = "lib"
41-
runtime = "nodejs12.x"
41+
runtime = "nodejs16.x"
4242
handler = "index.handler"
4343
event_type = "viewer-response"
4444
include_body = false
4545
},
4646
origin_request = {
4747
source_zip = "origin-request.zip"
48-
runtime = "nodejs12.x"
48+
runtime = "nodejs16.x"
4949
handler = "index.handler"
5050
event_type = "origin-request"
5151
include_body = false
@@ -77,7 +77,7 @@ module "lambda_at_edge" {
7777
EOT
7878
filename = "index.js"
7979
}]
80-
runtime = "nodejs12.x"
80+
runtime = "nodejs16.x"
8181
handler = "index.handler"
8282
event_type = "origin-response"
8383
include_body = false

examples/complete/main.tf

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ data "aws_iam_policy_document" "document" {
2020

2121
actions = ["s3:GetObject"]
2222
resources = [
23-
"arn:${join("", data.aws_partition.current.*.partition)}:s3:::$${bucket_name}$${origin_path}testprefix/*"
23+
"arn:${join("", data.aws_partition.current[*].partition)}:s3:::$${bucket_name}$${origin_path}testprefix/*"
2424
]
2525

2626
principals {
@@ -36,14 +36,16 @@ data "aws_canonical_user_id" "current" {
3636

3737
module "s3_bucket" {
3838
source = "cloudposse/s3-bucket/aws"
39-
version = "0.36.0"
39+
version = "3.1.2"
4040

41-
acl = null
42-
force_destroy = true
43-
user_enabled = false
44-
versioning_enabled = false
45-
attributes = ["existing-bucket"]
41+
force_destroy = true
42+
user_enabled = false
43+
versioning_enabled = false
44+
block_public_policy = false
45+
attributes = ["existing-bucket"]
4646

47+
acl = null
48+
s3_object_ownership = "BucketOwnerPreferred"
4749
grants = [
4850
{
4951
id = local.enabled ? data.aws_canonical_user_id.current[0].id : ""
@@ -62,9 +64,27 @@ module "s3_bucket" {
6264
context = module.this.context
6365
}
6466

67+
# Workaround for S3 eventual consistency for settings relating to objects
68+
resource "time_sleep" "wait_for_aws_s3_bucket_settings" {
69+
count = local.enabled ? 1 : 0
70+
71+
create_duration = "30s"
72+
destroy_duration = "30s"
73+
74+
depends_on = [
75+
data.aws_iam_policy_document.document,
76+
module.s3_bucket
77+
]
78+
}
79+
6580
module "cloudfront_s3_cdn" {
6681
source = "../../"
6782

83+
depends_on = [
84+
time_sleep.wait_for_aws_s3_bucket_settings,
85+
time_sleep.wait_for_additional_s3_origins
86+
]
87+
6888
parent_zone_name = var.parent_zone_name
6989
dns_alias_enabled = true
7090
origin_force_destroy = true
@@ -81,6 +101,7 @@ module "cloudfront_s3_cdn" {
81101

82102
cloudfront_access_logging_enabled = true
83103
cloudfront_access_log_prefix = "logs/cf_access"
104+
s3_object_ownership = "BucketOwnerPreferred"
84105

85106
additional_bucket_policy = local.enabled ? data.aws_iam_policy_document.document[0].json : ""
86107

@@ -105,7 +126,7 @@ module "cloudfront_s3_cdn" {
105126
context = module.this.context
106127
}
107128

108-
resource "aws_s3_bucket_object" "index" {
129+
resource "aws_s3_object" "index" {
109130
count = local.enabled ? 1 : 0
110131

111132
bucket = module.cloudfront_s3_cdn.s3_bucket

0 commit comments

Comments
 (0)