diff --git a/docs/discussions/knowledge-base/704.mdx b/docs/discussions/knowledge-base/704.mdx new file mode 100644 index 0000000000..562350f461 --- /dev/null +++ b/docs/discussions/knowledge-base/704.mdx @@ -0,0 +1,27 @@ +--- +hide_table_of_contents: true +hide_title: true +custom_edit_url: null +--- + +import CenterLayout from "/src/components/CenterLayout" +import GitHub from "/src/components/GitHub" + + + + + + +Knowledge Base +

How do I deploy an API gateway proxy properly with `configuration_aliases`?

+\n

Tracked in ticket #110135

\n\n","bodyHTML":"

A customer asked:

\n

We're trying to deploy an API gateway proxy with Gruntwork's module. The code we've created looks like this:

\n
terraform {\n  source = \"git::git@github.com:gruntwork-io/terraform-aws-lambda.git//modules/api-gateway-proxy?ref=v0.21.8\"\n  }\n   \n  # Include the `terragrunt.hcl` located in the root of our Reference Architecture's\n  # repository because this file contains all the templating required to make our\n  # Terraform state and AWS provider DRY.\n  include {\n  path = find_in_parent_folders()\n  }\n   \n  inputs = {\n    api_name = \"test-api\"\n    lambda_functions = {\n    \"\" = \"ingest-test\"\n  }\n}
\n
\n\n

Tracked in ticket #110135

\n
","answer":{"body":"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)\r\n\r\n[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: \r\n\r\n```HCL\r\n# ---------------------------------------------------------------------------------------------------------------------\r\n# USE API GATEWAY TO EXPOSE LAMBDA FUNCTION\r\n# ---------------------------------------------------------------------------------------------------------------------\r\n\r\nmodule \"api_gateway\" {\r\n # When using these modules in your own templates, you will need to use a Git URL with a ref attribute that pins you\r\n # to a specific version of the modules, such as the following example:\r\n # source = \"git::git@github.com:gruntwork-io/terraform-aws-lambda.git//modules/api-gateway-proxy?ref=v1.0.8\"\r\n source = \"../../../modules/api-gateway-proxy\"\r\n providers = {\r\n aws = aws\r\n\r\n # NOTE: this is only necessary if you are configuring an EDGE domain (globally optimized API Gateway endpoint using\r\n # CloudFront). For other cases, this can be configured to the base `aws` provider.\r\n aws.us_east_1 = aws.us_east_1\r\n }\r\n\r\n api_name = var.name\r\n lambda_functions = {\r\n # Empty string key means proxy everything\r\n \"\" = module.lambda.function_name\r\n }\r\n... truncated for brevity ...\r\n```\r\n\r\nHowever, 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)\r\n\r\nConversely, 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) \r\n\r\n\r\nTo make this one API proxy module work, for example, you'd need to generate a single `provider` block: \r\n\r\n```HCL\r\ngenerate \"providers\" {\r\n path = \"providers-custom.tf\"\r\n if_exists = \"overwrite\"\r\n contents = <Gruntwork's API Proxy module has a configuration_aliases config that requires a provider explicitly aliased to us_east_1 to be passed in.

\n

Here's an example in pure Terraform of how you would pass in such an alias:

\n
# ---------------------------------------------------------------------------------------------------------------------\n# USE API GATEWAY TO EXPOSE LAMBDA FUNCTION\n# ---------------------------------------------------------------------------------------------------------------------\n\nmodule \"api_gateway\" {\n  # When using these modules in your own templates, you will need to use a Git URL with a ref attribute that pins you\n  # to a specific version of the modules, such as the following example:\n  # source = \"git::git@github.com:gruntwork-io/terraform-aws-lambda.git//modules/api-gateway-proxy?ref=v1.0.8\"\n  source = \"../../../modules/api-gateway-proxy\"\n  providers = {\n    aws = aws\n\n    # NOTE: this is only necessary if you are configuring an EDGE domain (globally optimized API Gateway endpoint using\n    # CloudFront). For other cases, this can be configured to the base `aws` provider.\n    aws.us_east_1 = aws.us_east_1\n  }\n\n  api_name = var.name\n  lambda_functions = {\n    # Empty string key means proxy everything\n    \"\" = module.lambda.function_name\n  }\n... truncated for brevity ...
\n

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.

\n

Conversely, for multi-region modules, we generate a bunch of provider blocks, each with an alias.

\n

To make this one API proxy module work, for example, you'd need to generate a single provider block:

\n
generate \"providers\" {\n  path      = \"providers-custom.tf\"\n  if_exists = \"overwrite\"\n  contents  = <<EOF\nprovider \"aws\" {\n  region = \"us-east-1\"\n  alias = \"us_east_1\"\n}\nEOF\n}
"}}} /> + +
+ + +