From 3f10a70edc71c724efb31808e95a6a3f140c9a25 Mon Sep 17 00:00:00 2001 From: Ivo Durnik Date: Thu, 1 Aug 2024 11:58:23 +0200 Subject: [PATCH 1/3] fix: Do not create cors_configuration when not provided --- main.tf | 2 +- variables.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index ae05c10..e748555 100644 --- a/main.tf +++ b/main.tf @@ -16,7 +16,7 @@ resource "aws_apigatewayv2_api" "this" { body = local.is_http ? var.body : null dynamic "cors_configuration" { - for_each = local.is_http && length(var.cors_configuration) > 0 ? [var.cors_configuration] : [] + for_each = local.is_http && length({ for k, v in var.cors_configuration : k => v if v != null}) > 0 ? [var.cors_configuration] : [] content { allow_credentials = cors_configuration.value.allow_credentials diff --git a/variables.tf b/variables.tf index 841c070..1fa5392 100644 --- a/variables.tf +++ b/variables.tf @@ -27,7 +27,7 @@ variable "cors_configuration" { allow_headers = optional(list(string)) allow_methods = optional(list(string)) allow_origins = optional(list(string)) - expose_headers = optional(list(string), []) + expose_headers = optional(list(string)) max_age = optional(number) }) default = {} From b7ec703569f213a510721a884430865e59550cab Mon Sep 17 00:00:00 2001 From: Bryant Biggs Date: Fri, 2 Aug 2024 13:42:47 -0500 Subject: [PATCH 2/3] fix: Correct type to be `null` by default --- .pre-commit-config.yaml | 2 +- README.md | 2 +- main.tf | 2 +- variables.tf | 4 ++-- wrappers/README.md | 6 +++--- wrappers/main.tf | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b567c52..0983882 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/antonbabenko/pre-commit-terraform - rev: v1.92.0 + rev: v1.92.1 hooks: - id: terraform_fmt - id: terraform_wrapper_module_for_each diff --git a/README.md b/README.md index 77a79ef..76df66a 100644 --- a/README.md +++ b/README.md @@ -204,7 +204,7 @@ module "api_gateway" { | [api\_version](#input\_api\_version) | A version identifier for the API. Must be between 1 and 64 characters in length | `string` | `null` | no | | [authorizers](#input\_authorizers) | Map of API gateway authorizers to create |
map(object({
authorizer_credentials_arn = optional(string)
authorizer_payload_format_version = optional(string)
authorizer_result_ttl_in_seconds = optional(number)
authorizer_type = optional(string, "REQUEST")
authorizer_uri = optional(string)
enable_simple_responses = optional(bool)
identity_sources = optional(list(string))
jwt_configuration = optional(object({
audience = optional(list(string))
issuer = optional(string)
}))
name = optional(string)
}))
| `{}` | no | | [body](#input\_body) | An OpenAPI specification that defines the set of routes and integrations to create as part of the HTTP APIs. Supported only for HTTP APIs | `string` | `null` | no | -| [cors\_configuration](#input\_cors\_configuration) | The cross-origin resource sharing (CORS) configuration. Applicable for HTTP APIs |
object({
allow_credentials = optional(bool)
allow_headers = optional(list(string))
allow_methods = optional(list(string))
allow_origins = optional(list(string))
expose_headers = optional(list(string), [])
max_age = optional(number)
})
| `{}` | no | +| [cors\_configuration](#input\_cors\_configuration) | The cross-origin resource sharing (CORS) configuration. Applicable for HTTP APIs |
object({
allow_credentials = optional(bool)
allow_headers = optional(list(string))
allow_methods = optional(list(string))
allow_origins = optional(list(string))
expose_headers = optional(list(string), [])
max_age = optional(number)
})
| `null` | no | | [create](#input\_create) | Controls if resources should be created | `bool` | `true` | no | | [create\_certificate](#input\_create\_certificate) | Whether to create a certificate for the domain | `bool` | `true` | no | | [create\_domain\_name](#input\_create\_domain\_name) | Whether to create API domain name resource | `bool` | `true` | no | diff --git a/main.tf b/main.tf index e748555..4155162 100644 --- a/main.tf +++ b/main.tf @@ -16,7 +16,7 @@ resource "aws_apigatewayv2_api" "this" { body = local.is_http ? var.body : null dynamic "cors_configuration" { - for_each = local.is_http && length({ for k, v in var.cors_configuration : k => v if v != null}) > 0 ? [var.cors_configuration] : [] + for_each = local.is_http && var.cors_configuration != null ? [var.cors_configuration] : [] content { allow_credentials = cors_configuration.value.allow_credentials diff --git a/variables.tf b/variables.tf index 1fa5392..d9d6b11 100644 --- a/variables.tf +++ b/variables.tf @@ -27,10 +27,10 @@ variable "cors_configuration" { allow_headers = optional(list(string)) allow_methods = optional(list(string)) allow_origins = optional(list(string)) - expose_headers = optional(list(string)) + expose_headers = optional(list(string), []) max_age = optional(number) }) - default = {} + default = null } variable "credentials_arn" { diff --git a/wrappers/README.md b/wrappers/README.md index 40e4194..6d9dbed 100644 --- a/wrappers/README.md +++ b/wrappers/README.md @@ -12,9 +12,9 @@ This wrapper does not implement any extra functionality. ```hcl terraform { - source = "tfr:///terraform-aws-modules/apigateway-v2/aws//wrappers" + source = "tfr:///terraform-aws-modules/fix/aws//wrappers" # Alternative source: - # source = "git::git@github.com:terraform-aws-modules/terraform-aws-apigateway-v2.git//wrappers?ref=master" + # source = "git::git@github.com:terraform-aws-modules/terraform-aws-fix.git//wrappers?ref=master" } inputs = { @@ -42,7 +42,7 @@ inputs = { ```hcl module "wrapper" { - source = "terraform-aws-modules/apigateway-v2/aws//wrappers" + source = "terraform-aws-modules/fix/aws//wrappers" defaults = { # Default values create = true diff --git a/wrappers/main.tf b/wrappers/main.tf index 9111439..a445b7a 100644 --- a/wrappers/main.tf +++ b/wrappers/main.tf @@ -8,7 +8,7 @@ module "wrapper" { api_version = try(each.value.api_version, var.defaults.api_version, null) authorizers = try(each.value.authorizers, var.defaults.authorizers, {}) body = try(each.value.body, var.defaults.body, null) - cors_configuration = try(each.value.cors_configuration, var.defaults.cors_configuration, {}) + cors_configuration = try(each.value.cors_configuration, var.defaults.cors_configuration, null) create = try(each.value.create, var.defaults.create, true) create_certificate = try(each.value.create_certificate, var.defaults.create_certificate, true) create_domain_name = try(each.value.create_domain_name, var.defaults.create_domain_name, true) From b490ff8ee73040924f13c026da77182d16e1d233 Mon Sep 17 00:00:00 2001 From: Bryant Biggs Date: Fri, 2 Aug 2024 13:48:29 -0500 Subject: [PATCH 3/3] fix: Wrappers due to directory name --- wrappers/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wrappers/README.md b/wrappers/README.md index 6d9dbed..40e4194 100644 --- a/wrappers/README.md +++ b/wrappers/README.md @@ -12,9 +12,9 @@ This wrapper does not implement any extra functionality. ```hcl terraform { - source = "tfr:///terraform-aws-modules/fix/aws//wrappers" + source = "tfr:///terraform-aws-modules/apigateway-v2/aws//wrappers" # Alternative source: - # source = "git::git@github.com:terraform-aws-modules/terraform-aws-fix.git//wrappers?ref=master" + # source = "git::git@github.com:terraform-aws-modules/terraform-aws-apigateway-v2.git//wrappers?ref=master" } inputs = { @@ -42,7 +42,7 @@ inputs = { ```hcl module "wrapper" { - source = "terraform-aws-modules/fix/aws//wrappers" + source = "terraform-aws-modules/apigateway-v2/aws//wrappers" defaults = { # Default values create = true