Skip to content

Commit 942bc7b

Browse files
authored
Adding origin_access_control_id to custom_origins (#326)
* Adding origin_access_control_id to custom_origins fix specification fix specification 2 * Setting origin_access_control_id to empty string instead of null coderabbitai suggestions
1 parent 7a49fac commit 942bc7b

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

docs/terraform.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
| <a name="input_cors_max_age_seconds"></a> [cors\_max\_age\_seconds](#input\_cors\_max\_age\_seconds) | Time in seconds that browser can cache the response for S3 bucket | `number` | `3600` | no |
8989
| <a name="input_custom_error_response"></a> [custom\_error\_response](#input\_custom\_error\_response) | List of one or more custom error response element maps | <pre>list(object({<br> error_caching_min_ttl = string<br> error_code = string<br> response_code = string<br> response_page_path = string<br> }))</pre> | `[]` | no |
9090
| <a name="input_custom_origin_headers"></a> [custom\_origin\_headers](#input\_custom\_origin\_headers) | A list of origin header parameters that will be sent to origin | `list(object({ name = string, value = string }))` | `[]` | no |
91-
| <a name="input_custom_origins"></a> [custom\_origins](#input\_custom\_origins) | A list of additional custom website [origins](https://www.terraform.io/docs/providers/aws/r/cloudfront_distribution.html#origin-arguments) for this distribution. | <pre>list(object({<br> domain_name = string<br> origin_id = string<br> origin_path = string<br> custom_headers = list(object({<br> name = string<br> value = string<br> }))<br> custom_origin_config = object({<br> http_port = number<br> https_port = number<br> origin_protocol_policy = string<br> origin_ssl_protocols = list(string)<br> origin_keepalive_timeout = number<br> origin_read_timeout = number<br> })<br> }))</pre> | `[]` | no |
91+
| <a name="input_custom_origins"></a> [custom\_origins](#input\_custom\_origins) | A list of additional custom website [origins](https://www.terraform.io/docs/providers/aws/r/cloudfront_distribution.html#origin-arguments) for this distribution. | <pre>list(object({<br> domain_name = string<br> origin_id = string<br> origin_path = string<br> origin_access_control_id = string<br> custom_headers = list(object({<br> name = string<br> value = string<br> }))<br> custom_origin_config = object({<br> http_port = number<br> https_port = number<br> origin_protocol_policy = string<br> origin_ssl_protocols = list(string)<br> origin_keepalive_timeout = number<br> origin_read_timeout = number<br> })<br> }))</pre> | `[]` | no |
9292
| <a name="input_default_root_object"></a> [default\_root\_object](#input\_default\_root\_object) | Object that CloudFront return when requests the root URL | `string` | `"index.html"` | no |
9393
| <a name="input_default_ttl"></a> [default\_ttl](#input\_default\_ttl) | Default amount of time (in seconds) that an object is in a CloudFront cache | `number` | `60` | no |
9494
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |

examples/complete/custom-origins.tf

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
locals {
22
additional_custom_origins_enabled = local.enabled && var.additional_custom_origins_enabled
33
default_custom_origin_configuration = {
4-
domain_name = null
5-
origin_id = null
6-
origin_path = null
7-
custom_headers = []
4+
domain_name = null
5+
origin_id = null
6+
origin_path = null
7+
# Example configuration with Origin Access Control for Lambda@Edge:
8+
# origin_access_control_id = aws_cloudfront_origin_access_control.example.id
9+
origin_access_control_id = null
10+
custom_headers = []
811
custom_origin_config = {
912
http_port = 80
1013
https_port = 443

main.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,9 +551,10 @@ resource "aws_cloudfront_distribution" "default" {
551551
dynamic "origin" {
552552
for_each = var.custom_origins
553553
content {
554-
domain_name = origin.value.domain_name
555-
origin_id = origin.value.origin_id
556-
origin_path = lookup(origin.value, "origin_path", "")
554+
domain_name = origin.value.domain_name
555+
origin_id = origin.value.origin_id
556+
origin_path = lookup(origin.value, "origin_path", "")
557+
origin_access_control_id = lookup(origin.value, "origin_access_control_id", null)
557558
dynamic "custom_header" {
558559
for_each = lookup(origin.value, "custom_headers", [])
559560
content {

variables.tf

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,10 @@ variable "ordered_cache" {
446446

447447
variable "custom_origins" {
448448
type = list(object({
449-
domain_name = string
450-
origin_id = string
451-
origin_path = string
449+
domain_name = string
450+
origin_id = string
451+
origin_path = string
452+
origin_access_control_id = optional(string)
452453
custom_headers = list(object({
453454
name = string
454455
value = string
@@ -465,6 +466,8 @@ variable "custom_origins" {
465466
default = []
466467
description = <<-EOT
467468
A list of additional custom website [origins](https://www.terraform.io/docs/providers/aws/r/cloudfront_distribution.html#origin-arguments) for this distribution.
469+
The `origin_access_control_id` field specifies the Origin Access Control configuration to use for this origin.
470+
This is used to configure secure access between CloudFront and the origin.
468471
EOT
469472
}
470473

0 commit comments

Comments
 (0)