Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions docs/discussions/knowledge-base/704.mdx
Original file line number Diff line number Diff line change
@@ -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"

<head>
<link rel="canonical" href="https://github.com/gruntwork-io/knowledge-base/discussions/704" />
</head>

<CenterLayout>
<span className="searchCategory">Knowledge Base</span>
<h1>How do I deploy an API gateway proxy properly with `configuration_aliases`?</h1>
<GitHub discussion={{"id":"D_kwDOF8slf84ATpL3","number":704,"author":{"login":"zackproser"},"title":"How do I deploy an API gateway proxy properly with `configuration_aliases`?","body":"\nA customer asked: \r\n\r\nWe're trying to deploy an API gateway proxy with Gruntwork's module. The code we've created looks like this: \r\n\r\n```HCL\r\n\r\n\r\nterraform {\r\n  source = \"git::git@github.com:gruntwork-io/terraform-aws-lambda.git//modules/api-gateway-proxy?ref=v0.21.8\"\r\n  }\r\n   \r\n  # Include the `terragrunt.hcl` located in the root of our Reference Architecture's\r\n  # repository because this file contains all the templating required to make our\r\n  # Terraform state and AWS provider DRY.\r\n include {\r\n  path = find_in_parent_folders()\r\n  }\r\n   \r\n  inputs = {\r\n  api_name = \"test-api\"\r\n  lambda_functions = {\r\n  \"\" = \"ingest-test\"\r\n  }\r\n}\r\n```\r\n\n\n---\n\n<ins datetime=\"2023-05-01T14:22:21Z\">\n <p><a href=\"https://support.gruntwork.io/hc/requests/110135\">Tracked in ticket #110135</a></p>\n</ins>\n","bodyHTML":"<p dir=\"auto\">A customer asked:</p>\n<p dir=\"auto\">We're trying to deploy an API gateway proxy with Gruntwork's module. The code we've created looks like this:</p>\n<div class=\"highlight highlight-source-terraform notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"\n\nterraform {\n  source = &quot;git::git@github.com:gruntwork-io/terraform-aws-lambda.git//modules/api-gateway-proxy?ref=v0.21.8&quot;\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 = &quot;test-api&quot;\n  lambda_functions = {\n  &quot;&quot; = &quot;ingest-test&quot;\n  }\n}\"><pre class=\"notranslate\"><span class=\"pl-k\">terraform</span> {\n  source <span class=\"pl-k\">=</span> <span class=\"pl-s\"><span class=\"pl-pds\">\"</span>git::git@github.com:gruntwork-io/terraform-aws-lambda.git//modules/api-gateway-proxy?ref=v0.21.8<span class=\"pl-pds\">\"</span></span>\n  }\n   \n  <span class=\"pl-c\"><span class=\"pl-c\">#</span> Include the `terragrunt.hcl` located in the root of our Reference Architecture's</span>\n  <span class=\"pl-c\"><span class=\"pl-c\">#</span> repository because this file contains all the templating required to make our</span>\n  <span class=\"pl-c\"><span class=\"pl-c\">#</span> Terraform state and AWS provider DRY.</span>\n <span class=\"pl-en\">include</span> {\n  path <span class=\"pl-k\">=</span> <span class=\"pl-v\">find_in_parent_folders</span>()\n  }\n   \n  <span class=\"pl-v\"><span class=\"pl-smi\">inputs</span> <span class=\"pl-k\">= </span></span>{\n  api_name <span class=\"pl-k\">=</span> <span class=\"pl-s\"><span class=\"pl-pds\">\"</span>test-api<span class=\"pl-pds\">\"</span></span>\n  lambda_functions <span class=\"pl-k\">=</span> {\n  <span class=\"pl-pds\">\"</span><span class=\"pl-pds\">\"</span> <span class=\"pl-k\">=</span> <span class=\"pl-s\"><span class=\"pl-pds\">\"</span>ingest-test<span class=\"pl-pds\">\"</span></span>\n  }\n}</pre></div>\n<hr>\n<ins datetime=\"2023-05-01T14:22:21Z\">\n <p dir=\"auto\"><a href=\"https://support.gruntwork.io/hc/requests/110135\" rel=\"nofollow\">Tracked in ticket #110135</a></p>\n</ins>","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 = <<EOF\r\nprovider \"aws\" {\r\n region = \"us-east-1\"\r\n alias = \"us_east_1\"\r\n}\r\nEOF\r\n}\r\n```","bodyHTML":"<p dir=\"auto\">Gruntwork's API Proxy <a href=\"https://github.com/gruntwork-io/terraform-aws-lambda/blob/main/modules/api-gateway-proxy/main.tf#L19\">module has a <code class=\"notranslate\">configuration_aliases</code> config that requires a provider explicitly aliased to <code class=\"notranslate\">us_east_1</code> to be passed in. </a></p>\n<p dir=\"auto\"><a href=\"https://github.com/gruntwork-io/terraform-aws-lambda/blob/87cac16880b6216657ab481851a790ce68066b08/examples/lambda-service/edge/main.tf#L63-L65\">Here's an example</a> in pure Terraform of how you would pass in such an alias:</p>\n<div class=\"highlight highlight-source-terraform notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"# ---------------------------------------------------------------------------------------------------------------------\n# USE API GATEWAY TO EXPOSE LAMBDA FUNCTION\n# ---------------------------------------------------------------------------------------------------------------------\n\nmodule &quot;api_gateway&quot; {\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 = &quot;git::git@github.com:gruntwork-io/terraform-aws-lambda.git//modules/api-gateway-proxy?ref=v1.0.8&quot;\n source = &quot;../../../modules/api-gateway-proxy&quot;\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 &quot;&quot; = module.lambda.function_name\n }\n... truncated for brevity ...\"><pre class=\"notranslate\"><span class=\"pl-c\"><span class=\"pl-c\">#</span> ---------------------------------------------------------------------------------------------------------------------</span>\n<span class=\"pl-c\"><span class=\"pl-c\">#</span> USE API GATEWAY TO EXPOSE LAMBDA FUNCTION</span>\n<span class=\"pl-c\"><span class=\"pl-c\">#</span> ---------------------------------------------------------------------------------------------------------------------</span>\n\n<span class=\"pl-k\">module</span> <span class=\"pl-s\"><span class=\"pl-pds\">\"</span>api_gateway<span class=\"pl-pds\">\"</span></span> {\n <span class=\"pl-c\"><span class=\"pl-c\">#</span> When using these modules in your own templates, you will need to use a Git URL with a ref attribute that pins you</span>\n <span class=\"pl-c\"><span class=\"pl-c\">#</span> to a specific version of the modules, such as the following example:</span>\n <span class=\"pl-c\"><span class=\"pl-c\">#</span> source = \"git::git@github.com:gruntwork-io/terraform-aws-lambda.git//modules/api-gateway-proxy?ref=v1.0.8\"</span>\n source <span class=\"pl-k\">=</span> <span class=\"pl-s\"><span class=\"pl-pds\">\"</span>../../../modules/api-gateway-proxy<span class=\"pl-pds\">\"</span></span>\n providers <span class=\"pl-k\">=</span> {\n aws <span class=\"pl-k\">=</span> aws\n\n <span class=\"pl-c\"><span class=\"pl-c\">#</span> NOTE: this is only necessary if you are configuring an EDGE domain (globally optimized API Gateway endpoint using</span>\n <span class=\"pl-c\"><span class=\"pl-c\">#</span> CloudFront). For other cases, this can be configured to the base `aws` provider.</span>\n aws<span class=\"pl-k\">.</span><span class=\"pl-smi\">us_east_1</span> = aws<span class=\"pl-k\">.</span><span class=\"pl-smi\">us_east_1</span>\n }\n\n api_name <span class=\"pl-k\">=</span> <span class=\"pl-c1\">var</span><span class=\"pl-k\">.</span><span class=\"pl-smi\">name</span>\n lambda_functions <span class=\"pl-k\">=</span> {\n <span class=\"pl-c\"><span class=\"pl-c\">#</span> Empty string key means proxy everything</span>\n <span class=\"pl-pds\">\"</span><span class=\"pl-pds\">\"</span> <span class=\"pl-k\">=</span> <span class=\"pl-c1\">module</span><span class=\"pl-k\">.</span><span class=\"pl-smi\">lambda</span><span class=\"pl-k\">.</span><span class=\"pl-smi\">function_name</span>\n }\n<span class=\"pl-k\">...</span> truncated <span class=\"pl-k\">for</span> <span class=\"pl-smi\">brevity</span> <span class=\"pl-k\">...</span></pre></div>\n<p dir=\"auto\">However, when working with Terragrunt code, we use <code class=\"notranslate\">generate</code> blocks to create the <code class=\"notranslate\">provider</code> blocks we need. By default, with the Reference Architecture, <a href=\"https://github.com/gruntwork-io/terraform-aws-service-catalog/blob/6a7a615ce63c3275359b8afaf0d119477628b188/examples/for-production/infrastructure-live/terragrunt.hcl#L34-L45\">we only generate a single such <code class=\"notranslate\">provider</code> block and it has no alias. </a></p>\n<p dir=\"auto\">Conversely, for multi-region modules, <a href=\"https://github.com/gruntwork-io/terraform-aws-service-catalog/blob/6a7a615ce63c3275359b8afaf0d119477628b188/examples/for-production/infrastructure-live/security/_global/account-baseline/terragrunt.hcl#L43-L63\">we generate a bunch of <code class=\"notranslate\">provider</code> blocks, each with an alias.</a></p>\n<p dir=\"auto\">To make this one API proxy module work, for example, you'd need to generate a single <code class=\"notranslate\">provider</code> block:</p>\n<div class=\"highlight highlight-source-terraform notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"generate &quot;providers&quot; {\n path = &quot;providers-custom.tf&quot;\n if_exists = &quot;overwrite&quot;\n contents = &lt;&lt;EOF\nprovider &quot;aws&quot; {\n region = &quot;us-east-1&quot;\n alias = &quot;us_east_1&quot;\n}\nEOF\n}\"><pre class=\"notranslate\"><span class=\"pl-en\">generate</span> <span class=\"pl-s\"><span class=\"pl-pds\">\"</span>providers<span class=\"pl-pds\">\"</span></span> {\n path <span class=\"pl-k\">=</span> <span class=\"pl-s\"><span class=\"pl-pds\">\"</span>providers-custom.tf<span class=\"pl-pds\">\"</span></span>\n if_exists <span class=\"pl-k\">=</span> <span class=\"pl-s\"><span class=\"pl-pds\">\"</span>overwrite<span class=\"pl-pds\">\"</span></span>\n contents <span class=\"pl-k\">=</span> <span class=\"pl-s\"><span class=\"pl-k\">&lt;&lt;</span><span class=\"pl-k\">EOF</span></span>\n<span class=\"pl-s\">provider \"aws\" {</span>\n<span class=\"pl-s\"> region = \"us-east-1\"</span>\n<span class=\"pl-s\"> alias = \"us_east_1\"</span>\n<span class=\"pl-s\">}</span>\n<span class=\"pl-s\"><span class=\"pl-k\">EOF</span></span>\n}</pre></div>"}}} />

</CenterLayout>


<!-- ##DOCS-SOURCER-START
{
"sourcePlugin": "github-discussions",
"hash": "4caa359701079d3902168bf61a3e29b4"
}
##DOCS-SOURCER-END -->