Skip to content

Commit 2f2a7ce

Browse files
committed
fix: Update variable name and tweak logic slightly
1 parent f06304f commit 2f2a7ce

File tree

11 files changed

+20
-39
lines changed

11 files changed

+20
-39
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.103.0
3+
rev: v1.104.0
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_wrapper_module_for_each

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ ordered_cache_behavior = [{
107107
| Name | Version |
108108
|------|---------|
109109
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5.7 |
110-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.83 |
110+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.100 |
111111

112112
## Providers
113113

114114
| Name | Version |
115115
|------|---------|
116-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.83 |
116+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.100 |
117117

118118
## Modules
119119

@@ -161,7 +161,7 @@ No modules.
161161
| <a name="input_origin_group"></a> [origin\_group](#input\_origin\_group) | One or more origin\_group for this distribution (multiples allowed). | `any` | `{}` | no |
162162
| <a name="input_price_class"></a> [price\_class](#input\_price\_class) | The price class for this distribution. One of PriceClass\_All, PriceClass\_200, PriceClass\_100 | `string` | `null` | no |
163163
| <a name="input_realtime_metrics_subscription_status"></a> [realtime\_metrics\_subscription\_status](#input\_realtime\_metrics\_subscription\_status) | A flag that indicates whether additional CloudWatch metrics are enabled for a given CloudFront distribution. Valid values are `Enabled` and `Disabled`. | `string` | `"Enabled"` | no |
164-
| <a name="input_response_headers_policy"></a> [response\_headers\_policy](#input\_response\_headers\_policy) | Map of CloudFront response headers policies with their configurations | <pre>map(object({<br/> name = optional(string)<br/> comment = optional(string)<br/><br/> cors_config = optional(object({<br/> access_control_allow_credentials = bool<br/> origin_override = bool<br/> access_control_allow_headers = object({<br/> items = list(string)<br/> })<br/> access_control_allow_methods = object({<br/> items = list(string)<br/> })<br/> access_control_allow_origins = object({<br/> items = list(string)<br/> })<br/> access_control_expose_headers = optional(object({<br/> items = list(string)<br/> }))<br/> access_control_max_age_sec = optional(number)<br/> }))<br/><br/> custom_headers_config = optional(object({<br/> items = list(object({<br/> header = string<br/> override = bool<br/> value = string<br/> }))<br/> }))<br/><br/> remove_headers_config = optional(object({<br/> items = list(object({<br/> header = string<br/> }))<br/> }))<br/><br/> security_headers_config = optional(object({<br/> content_security_policy = optional(object({<br/> content_security_policy = string<br/> override = bool<br/> }))<br/> content_type_options = optional(object({<br/> override = bool<br/> }))<br/> frame_options = optional(object({<br/> frame_option = string<br/> override = bool<br/> }))<br/> referrer_policy = optional(object({<br/> referrer_policy = string<br/> override = bool<br/> }))<br/> strict_transport_security = optional(object({<br/> access_control_max_age_sec = number<br/> override = bool<br/> include_subdomains = optional(bool)<br/> preload = optional(bool)<br/> }))<br/> xss_protection = optional(object({<br/> mode_block = bool<br/> override = bool<br/> protection = bool<br/> report_uri = optional(string)<br/> }))<br/> }))<br/><br/> server_timing_headers_config = optional(object({<br/> enabled = bool<br/> sampling_rate = number<br/> }))<br/> }))</pre> | `{}` | no |
164+
| <a name="input_response_headers_policies"></a> [response\_headers\_policies](#input\_response\_headers\_policies) | Map of CloudFront response headers policies with their configurations | <pre>map(object({<br/> name = optional(string)<br/> comment = optional(string)<br/> cors_config = optional(object({<br/> access_control_allow_credentials = bool<br/> origin_override = bool<br/> access_control_allow_headers = object({<br/> items = list(string)<br/> })<br/> access_control_allow_methods = object({<br/> items = list(string)<br/> })<br/> access_control_allow_origins = object({<br/> items = list(string)<br/> })<br/> access_control_expose_headers = optional(object({<br/> items = list(string)<br/> }))<br/> access_control_max_age_sec = optional(number)<br/> }))<br/> custom_headers_config = optional(object({<br/> items = list(object({<br/> header = string<br/> override = bool<br/> value = string<br/> }))<br/> }))<br/> remove_headers_config = optional(object({<br/> items = list(object({<br/> header = string<br/> }))<br/> }))<br/> security_headers_config = optional(object({<br/> content_security_policy = optional(object({<br/> content_security_policy = string<br/> override = bool<br/> }))<br/> content_type_options = optional(object({<br/> override = bool<br/> }))<br/> frame_options = optional(object({<br/> frame_option = string<br/> override = bool<br/> }))<br/> referrer_policy = optional(object({<br/> referrer_policy = string<br/> override = bool<br/> }))<br/> strict_transport_security = optional(object({<br/> access_control_max_age_sec = number<br/> override = bool<br/> include_subdomains = optional(bool)<br/> preload = optional(bool)<br/> }))<br/> xss_protection = optional(object({<br/> mode_block = bool<br/> override = bool<br/> protection = bool<br/> report_uri = optional(string)<br/> }))<br/> }))<br/> server_timing_headers_config = optional(object({<br/> enabled = bool<br/> sampling_rate = number<br/> }))<br/> }))</pre> | `null` | no |
165165
| <a name="input_retain_on_delete"></a> [retain\_on\_delete](#input\_retain\_on\_delete) | Disables the distribution instead of deleting it when destroying the resource through Terraform. If this is set, the distribution needs to be deleted manually afterwards. | `bool` | `false` | no |
166166
| <a name="input_staging"></a> [staging](#input\_staging) | Whether the distribution is a staging distribution. | `bool` | `false` | no |
167167
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to assign to the resource. | `map(string)` | `null` | no |
@@ -193,8 +193,6 @@ No modules.
193193
| <a name="output_cloudfront_origin_access_identity_iam_arns"></a> [cloudfront\_origin\_access\_identity\_iam\_arns](#output\_cloudfront\_origin\_access\_identity\_iam\_arns) | The IAM arns of the origin access identities created |
194194
| <a name="output_cloudfront_origin_access_identity_ids"></a> [cloudfront\_origin\_access\_identity\_ids](#output\_cloudfront\_origin\_access\_identity\_ids) | The IDS of the origin access identities created |
195195
| <a name="output_cloudfront_response_headers_policies"></a> [cloudfront\_response\_headers\_policies](#output\_cloudfront\_response\_headers\_policies) | The response headers policies created |
196-
| <a name="output_cloudfront_response_headers_policy_etags"></a> [cloudfront\_response\_headers\_policy\_etags](#output\_cloudfront\_response\_headers\_policy\_etags) | The ETags of the response headers policies created |
197-
| <a name="output_cloudfront_response_headers_policy_ids"></a> [cloudfront\_response\_headers\_policy\_ids](#output\_cloudfront\_response\_headers\_policy\_ids) | The IDs of the response headers policies created |
198196
| <a name="output_cloudfront_vpc_origin_ids"></a> [cloudfront\_vpc\_origin\_ids](#output\_cloudfront\_vpc\_origin\_ids) | The IDS of the VPC origin created |
199197
<!-- END_TF_DOCS -->
200198

examples/complete/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ Note that this example may create resources which cost money. Run `terraform des
2828
| Name | Version |
2929
|------|---------|
3030
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5.7 |
31-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.83 |
31+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.100 |
3232
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 2.0 |
3333
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 |
3434

3535
## Providers
3636

3737
| Name | Version |
3838
|------|---------|
39-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.83 |
39+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.100 |
4040
| <a name="provider_null"></a> [null](#provider\_null) | >= 2.0 |
4141
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 |
4242

examples/complete/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ module "cloudfront" {
234234
}
235235

236236
create_response_headers_policy = true
237-
response_headers_policy = {
237+
response_headers_policies = {
238238
cors_policy = {
239239
name = "CORSPolicy"
240240
comment = "CORS configuration for API"

examples/complete/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.83"
7+
version = ">= 5.100"
88
}
99
random = {
1010
source = "hashicorp/random"

main.tf

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
locals {
2-
create_origin_access_identity = var.create_origin_access_identity && length(keys(var.origin_access_identities)) > 0
3-
create_origin_access_control = var.create_origin_access_control && length(keys(var.origin_access_control)) > 0
4-
create_vpc_origin = var.create_vpc_origin && length(keys(var.vpc_origin)) > 0
5-
create_response_headers_policy = var.create_response_headers_policy && length(keys(var.response_headers_policy)) > 0
2+
create_origin_access_identity = var.create_origin_access_identity && length(keys(var.origin_access_identities)) > 0
3+
create_origin_access_control = var.create_origin_access_control && length(keys(var.origin_access_control)) > 0
4+
create_vpc_origin = var.create_vpc_origin && length(keys(var.vpc_origin)) > 0
65
}
76

87
resource "aws_cloudfront_response_headers_policy" "this" {
9-
for_each = local.create_response_headers_policy ? var.response_headers_policy : {}
8+
for_each = var.create_response_headers_policy && var.response_headers_policies != null ? var.response_headers_policies : {}
109

11-
name = each.value.name != null ? each.value.name : each.key
10+
name = try(coalesce(each.value.name, each.key))
1211
comment = each.value.comment
1312

1413
dynamic "cors_config" {
@@ -17,7 +16,7 @@ resource "aws_cloudfront_response_headers_policy" "this" {
1716
content {
1817
access_control_allow_credentials = cors_config.value.access_control_allow_credentials
1918
origin_override = cors_config.value.origin_override
20-
access_control_max_age_sec = cors_config.value.access_control_max_age_sec != null ? cors_config.value.access_control_max_age_sec : null
19+
access_control_max_age_sec = cors_config.value.access_control_max_age_sec
2120

2221
access_control_allow_headers {
2322
items = cors_config.value.access_control_allow_headers.items
@@ -144,7 +143,6 @@ resource "aws_cloudfront_response_headers_policy" "this" {
144143
}
145144
}
146145

147-
148146
resource "aws_cloudfront_origin_access_identity" "this" {
149147
for_each = local.create_origin_access_identity ? var.origin_access_identities : {}
150148

outputs.tf

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,5 @@ output "cloudfront_vpc_origin_ids" {
9090

9191
output "cloudfront_response_headers_policies" {
9292
description = "The response headers policies created"
93-
value = local.create_response_headers_policy ? { for k, v in aws_cloudfront_response_headers_policy.this : k => v } : {}
94-
}
95-
96-
output "cloudfront_response_headers_policy_ids" {
97-
description = "The IDs of the response headers policies created"
98-
value = local.create_response_headers_policy ? { for k, v in aws_cloudfront_response_headers_policy.this : k => v.id } : {}
99-
}
100-
101-
output "cloudfront_response_headers_policy_etags" {
102-
description = "The ETags of the response headers policies created"
103-
value = local.create_response_headers_policy ? { for k, v in aws_cloudfront_response_headers_policy.this : k => v.etag } : {}
93+
value = aws_cloudfront_response_headers_policy.this
10494
}

variables.tf

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,11 @@ variable "create_response_headers_policy" {
217217
default = false
218218
}
219219

220-
variable "response_headers_policy" {
220+
variable "response_headers_policies" {
221221
description = "Map of CloudFront response headers policies with their configurations"
222222
type = map(object({
223223
name = optional(string)
224224
comment = optional(string)
225-
226225
cors_config = optional(object({
227226
access_control_allow_credentials = bool
228227
origin_override = bool
@@ -240,21 +239,18 @@ variable "response_headers_policy" {
240239
}))
241240
access_control_max_age_sec = optional(number)
242241
}))
243-
244242
custom_headers_config = optional(object({
245243
items = list(object({
246244
header = string
247245
override = bool
248246
value = string
249247
}))
250248
}))
251-
252249
remove_headers_config = optional(object({
253250
items = list(object({
254251
header = string
255252
}))
256253
}))
257-
258254
security_headers_config = optional(object({
259255
content_security_policy = optional(object({
260256
content_security_policy = string
@@ -284,11 +280,10 @@ variable "response_headers_policy" {
284280
report_uri = optional(string)
285281
}))
286282
}))
287-
288283
server_timing_headers_config = optional(object({
289284
enabled = bool
290285
sampling_rate = number
291286
}))
292287
}))
293-
default = {}
288+
default = null
294289
}

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.83"
7+
version = ">= 5.100"
88
}
99
}
1010
}

wrappers/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module "wrapper" {
3434
origin_group = try(each.value.origin_group, var.defaults.origin_group, {})
3535
price_class = try(each.value.price_class, var.defaults.price_class, null)
3636
realtime_metrics_subscription_status = try(each.value.realtime_metrics_subscription_status, var.defaults.realtime_metrics_subscription_status, "Enabled")
37-
response_headers_policy = try(each.value.response_headers_policy, var.defaults.response_headers_policy, {})
37+
response_headers_policies = try(each.value.response_headers_policies, var.defaults.response_headers_policies, null)
3838
retain_on_delete = try(each.value.retain_on_delete, var.defaults.retain_on_delete, false)
3939
staging = try(each.value.staging, var.defaults.staging, false)
4040
tags = try(each.value.tags, var.defaults.tags, null)

0 commit comments

Comments
 (0)