Skip to content

Commit 4c60c05

Browse files
author
Artem Timofeev
committed
feat(origin_groups): added support for custom origin group ids
1 parent 9a65f7e commit 4c60c05

File tree

5 files changed

+6
-2
lines changed

5 files changed

+6
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ module "cdn" {
122122
}
123123
}]
124124
origin_groups = [{
125+
group_id = "groupS3"
125126
primary_origin_id = null # will get translated to the origin id of the origin created by this module.
126127
failover_origin_id = module.s3_bucket.bucket_id
127128
failover_criteria = [
@@ -524,7 +525,7 @@ module "cdn" {
524525
| <a name="input_origin_access_type"></a> [origin\_access\_type](#input\_origin\_access\_type) | Choose to use `origin_access_control` or `orgin_access_identity` | `string` | `"origin_access_identity"` | no |
525526
| <a name="input_origin_bucket"></a> [origin\_bucket](#input\_origin\_bucket) | Name of an existing S3 bucket to use as the origin. If this is not provided, it will create a new s3 bucket using `var.name` and other context related inputs | `string` | `null` | no |
526527
| <a name="input_origin_force_destroy"></a> [origin\_force\_destroy](#input\_origin\_force\_destroy) | Delete all objects from the bucket so that the bucket can be destroyed without error (e.g. `true` or `false`) | `bool` | `false` | no |
527-
| <a name="input_origin_groups"></a> [origin\_groups](#input\_origin\_groups) | List of [Origin Groups](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_distribution#origin-group-arguments) to create in the distribution.<br/>The values of `primary_origin_id` and `failover_origin_id` must correspond to origin IDs existing in `var.s3_origins` or `var.custom_origins`.<br/><br/>If `primary_origin_id` is set to `null` or `""`, then the origin id of the origin created by this module will be used in its place.<br/>This is to allow for the use case of making the origin created by this module the primary origin in an origin group. | <pre>list(object({<br/> primary_origin_id = string<br/> failover_origin_id = string<br/> failover_criteria = list(string)<br/> }))</pre> | `[]` | no |
528+
| <a name="input_origin_groups"></a> [origin\_groups](#input\_origin\_groups) | List of [Origin Groups](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_distribution#origin-group-arguments) to create in the distribution.<br/>The values of `primary_origin_id` and `failover_origin_id` must correspond to origin IDs existing in `var.s3_origins` or `var.custom_origins`.<br/><br/>If `primary_origin_id` is set to `null` or `""`, then the origin id of the origin created by this module will be used in its place.<br/>This is to allow for the use case of making the origin created by this module the primary origin in an origin group. | <pre>list(object({<br/> group_id = optional(string)<br/> primary_origin_id = string<br/> failover_origin_id = string<br/> failover_criteria = list(string)<br/> }))</pre> | `[]` | no |
528529
| <a name="input_origin_path"></a> [origin\_path](#input\_origin\_path) | An optional element that causes CloudFront to request your content from a directory in your Amazon S3 bucket or your custom origin. It must begin with a /. Do not add a / at the end of the path. | `string` | `""` | no |
529530
| <a name="input_origin_request_policy_id"></a> [origin\_request\_policy\_id](#input\_origin\_request\_policy\_id) | The unique identifier of the origin request policy that is attached to the behavior.<br/>Should be used in conjunction with `cache_policy_id`. | `string` | `null` | no |
530531
| <a name="input_origin_shield_enabled"></a> [origin\_shield\_enabled](#input\_origin\_shield\_enabled) | If enabled, origin shield will be enabled for the default origin | `bool` | `false` | no |

README.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ usage: |2-
131131
}
132132
}]
133133
origin_groups = [{
134+
group_id = "groupS3"
134135
primary_origin_id = null # will get translated to the origin id of the origin created by this module.
135136
failover_origin_id = module.s3_bucket.bucket_id
136137
failover_criteria = [

examples/complete/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ module "cloudfront_s3_cdn" {
118118
}
119119
}], var.additional_s3_origins_enabled ? [local.additional_s3_origin_primary, local.additional_s3_origin_secondary] : [])
120120
origin_groups = concat([{
121+
group_id = "groupS3"
121122
primary_origin_id = null # will get translated to the origin id of the origin created by this module.
122123
failover_origin_id = module.s3_bucket.bucket_id
123124
failover_criteria = var.origin_group_failover_criteria_status_codes

main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ resource "aws_cloudfront_distribution" "default" {
489489
dynamic "origin_group" {
490490
for_each = var.origin_groups
491491
content {
492-
origin_id = "${module.this.id}-group[${origin_group.key}]"
492+
origin_id = try(length(origin_group.value.group_id), 0) > 0 ? origin_group.value.group_id : "${module.this.id}-group[${origin_group.key}]"
493493

494494
failover_criteria {
495495
status_codes = origin_group.value.failover_criteria

variables.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ variable "s3_website_password_enabled" {
653653

654654
variable "origin_groups" {
655655
type = list(object({
656+
group_id = optional(string)
656657
primary_origin_id = string
657658
failover_origin_id = string
658659
failover_criteria = list(string)

0 commit comments

Comments
 (0)