How do I deploy an API gateway proxy properly with configuration_aliases?
A customer asked: We're trying to deploy an API gateway proxy with Gruntwork's module. The code we've created looks like this: ```HCL terraform { source = "git::git@github.com:gruntwork-io/terraform-aws-lambda.git//modules/api-gateway-proxy?ref=v0.21.8" } # Include the `terragrunt.hcl` located in the root of our Reference Architecture's # repository because this file contains all the templating required to make our # Terraform state and AWS provider DRY. include { path = find_in_parent_folders() } inputs = { api_name = "test-api" lambda_functions = { "" = "ingest-test" } } ``` --- <ins datetime="2023-05-01T14:22:21Z"> <p><a href="https://support.gruntwork.io/hc/requests/110135">Tracked in ticket #110135</a></p> </ins>
Gruntwork's API Proxy [module has a `configuration_aliases` config that requires a provider explicitly aliased to `us_east_1` to be passed in. ](https://github.com/gruntwork-io/terraform-aws-lambda/blob/main/modules/api-gateway-proxy/main.tf#L19) [Here's an example](https://github.com/gruntwork-io/terraform-aws-lambda/blob/87cac16880b6216657ab481851a790ce68066b08/examples/lambda-service/edge/main.tf#L63-L65) in pure Terraform of how you would pass in such an alias: ```HCL # --------------------------------------------------------------------------------------------------------------------- # USE API GATEWAY TO EXPOSE LAMBDA FUNCTION # --------------------------------------------------------------------------------------------------------------------- module "api_gateway" { # When using these modules in your own templates, you will need to use a Git URL with a ref attribute that pins you # to a specific version of the modules, such as the following example: # source = "git::git@github.com:gruntwork-io/terraform-aws-lambda.git//modules/api-gateway-proxy?ref=v1.0.8" source = "../../../modules/api-gateway-proxy" providers = { aws = aws # NOTE: this is only necessary if you are configuring an EDGE domain (globally optimized API Gateway endpoint using # CloudFront). For other cases, this can be configured to the base `aws` provider. aws.us_east_1 = aws.us_east_1 } api_name = var.name lambda_functions = { # Empty string key means proxy everything "" = module.lambda.function_name } ... truncated for brevity ... ``` However, when working with Terragrunt code, we use `generate` blocks to create the `provider` blocks we need. By default, with the Reference Architecture, [we only generate a single such `provider` block and it has no alias. ](https://github.com/gruntwork-io/terraform-aws-service-catalog/blob/6a7a615ce63c3275359b8afaf0d119477628b188/examples/for-production/infrastructure-live/terragrunt.hcl#L34-L45) Conversely, for multi-region modules, [we generate a bunch of `provider` blocks, each with an alias.](https://github.com/gruntwork-io/terraform-aws-service-catalog/blob/6a7a615ce63c3275359b8afaf0d119477628b188/examples/for-production/infrastructure-live/security/_global/account-baseline/terragrunt.hcl#L43-L63) To make this one API proxy module work, for example, you'd need to generate a single `provider` block: ```HCL generate "providers" { path = "providers-custom.tf" if_exists = "overwrite" contents = <<EOF provider "aws" { region = "us-east-1" alias = "us_east_1" } EOF } ```