Skip to content

Commit

Permalink
Adding trusted_key_groups to default behavior (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
adenot authored Nov 11, 2024
1 parent e790f21 commit ed37b74
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
11 changes: 10 additions & 1 deletion _variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,13 @@ The following arguments are supported:
- actions: The actions to execute when the alarm transitions into an ALARM state (ARN).
- ok_actions: The list of actions to execute when this alarm transitions into an OK state from any other state (ARN).
EOF
}
}

variable "trusted_key_groups" {
type = list(object({
name = string
public_key_contents = string
}))
default = []
description = "A list with `name` and `public_key` to create and attach a trusted key group to the distribution"
}
1 change: 1 addition & 0 deletions cloudfront.tf
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ resource "aws_cloudfront_distribution" "default" {
target_origin_id = "s3Origin"
compress = true
response_headers_policy_id = var.default_cache_behavior_response_headers_id
trusted_key_groups = length(var.trusted_key_groups) > 0 ? [for i in aws_cloudfront_key_group.default : i.id] : []

forwarded_values {
query_string = var.default_cache_behavior_forward_query_string
Expand Down
13 changes: 13 additions & 0 deletions key_groups.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
resource "aws_cloudfront_public_key" "default" {
for_each = { for public_key in var.trusted_key_groups : public_key.name => public_key }
comment = ""
encoded_key = each.value.public_key_contents
name = each.key
}

resource "aws_cloudfront_key_group" "default" {
for_each = { for public_key in var.trusted_key_groups : public_key.name => public_key }
comment = ""
items = [aws_cloudfront_public_key.default[each.key].id]
name = each.key
}

0 comments on commit ed37b74

Please sign in to comment.