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" + +
+ + + +A customer asked:
\nWe're trying to deploy an API gateway proxy with Gruntwork's module. The code we've created looks like this:
\nterraform {\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}configuration_aliases config that requires a provider explicitly aliased to us_east_1 to be passed in. \nHere'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 ...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.
Conversely, for multi-region modules, we generate a bunch of provider blocks, each with an alias.
To make this one API proxy module work, for example, you'd need to generate a single provider block:
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}