Skip to content

Commit 055f54d

Browse files
authored
Merge branch 'main' into fix/bug-257
2 parents 8a1441a + 1dc4708 commit 055f54d

19 files changed

+1052
-461
lines changed

.github/workflows/feature-branch.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
permissions:
1111
pull-requests: write
1212
id-token: write
13-
contents: read
13+
contents: write
1414

1515
jobs:
1616
terraform-module:

.github/workflows/release-branch.yml

+1
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

+1-1
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

+5-9
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

@@ -501,7 +497,7 @@ Available targets:
501497
| <a name="input_cloudfront_access_logging_enabled"></a> [cloudfront\_access\_logging\_enabled](#input\_cloudfront\_access\_logging\_enabled) | Set true to enable delivery of Cloudfront Access Logs to an S3 bucket | `bool` | `true` | no |
502498
| <a name="input_cloudfront_origin_access_identity_iam_arn"></a> [cloudfront\_origin\_access\_identity\_iam\_arn](#input\_cloudfront\_origin\_access\_identity\_iam\_arn) | Existing cloudfront origin access identity iam arn that is supplied in the s3 bucket policy | `string` | `""` | no |
503499
| <a name="input_cloudfront_origin_access_identity_path"></a> [cloudfront\_origin\_access\_identity\_path](#input\_cloudfront\_origin\_access\_identity\_path) | Existing cloudfront origin access identity path used in the cloudfront distribution's s3\_origin\_config content | `string` | `""` | no |
504-
| <a name="input_comment"></a> [comment](#input\_comment) | Comment for the origin access identity | `string` | `"Managed by Terraform"` | no |
500+
| <a name="input_comment"></a> [comment](#input\_comment) | Comment for the CloudFront distribution | `string` | `"Managed by Terraform"` | no |
505501
| <a name="input_compress"></a> [compress](#input\_compress) | Compress content for web requests that include Accept-Encoding: gzip in the request header | `bool` | `true` | no |
506502
| <a name="input_context"></a> [context](#input\_context) | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "descriptor_formats": {},<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "labels_as_tags": [<br> "unset"<br> ],<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {},<br> "tenant": null<br>}</pre> | no |
507503
| <a name="input_cors_allowed_headers"></a> [cors\_allowed\_headers](#input\_cors\_allowed\_headers) | List of allowed headers for S3 bucket | `list(string)` | <pre>[<br> "*"<br>]</pre> | no |

README.yaml

+1-1
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

+4-4
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

@@ -69,7 +69,7 @@
6969
| <a name="input_cloudfront_access_logging_enabled"></a> [cloudfront\_access\_logging\_enabled](#input\_cloudfront\_access\_logging\_enabled) | Set true to enable delivery of Cloudfront Access Logs to an S3 bucket | `bool` | `true` | no |
7070
| <a name="input_cloudfront_origin_access_identity_iam_arn"></a> [cloudfront\_origin\_access\_identity\_iam\_arn](#input\_cloudfront\_origin\_access\_identity\_iam\_arn) | Existing cloudfront origin access identity iam arn that is supplied in the s3 bucket policy | `string` | `""` | no |
7171
| <a name="input_cloudfront_origin_access_identity_path"></a> [cloudfront\_origin\_access\_identity\_path](#input\_cloudfront\_origin\_access\_identity\_path) | Existing cloudfront origin access identity path used in the cloudfront distribution's s3\_origin\_config content | `string` | `""` | no |
72-
| <a name="input_comment"></a> [comment](#input\_comment) | Comment for the origin access identity | `string` | `"Managed by Terraform"` | no |
72+
| <a name="input_comment"></a> [comment](#input\_comment) | Comment for the CloudFront distribution | `string` | `"Managed by Terraform"` | no |
7373
| <a name="input_compress"></a> [compress](#input\_compress) | Compress content for web requests that include Accept-Encoding: gzip in the request header | `bool` | `true` | no |
7474
| <a name="input_context"></a> [context](#input\_context) | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "descriptor_formats": {},<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "labels_as_tags": [<br> "unset"<br> ],<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {},<br> "tenant": null<br>}</pre> | no |
7575
| <a name="input_cors_allowed_headers"></a> [cors\_allowed\_headers](#input\_cors\_allowed\_headers) | List of allowed headers for S3 bucket | `list(string)` | <pre>[<br> "*"<br>]</pre> | no |

examples/complete/custom-origins.tf

+85-12
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

+1-1
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

+4-4
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

+29-8
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)