Error: Reference to undeclared resource (dependency) lambda and apigateway #689
Replies: 1 comment 1 reply
-
Hello,
I prepared a simplified example with passing variables in https://github.com/denis256/terragrunt-tests/tree/master/discussion-689, I hope it will be useful |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Apigw module is dependent to lambda module,
It look like terragrunt is not able to retrieve outputs from the state and parse it to dependency in terragrunt.hcl under apigw folder
Terragrunt codes:
.
├── apigw
│ └── terragrunt.hcl
├── env.hcl
├── graph.svg
└── lambda
├── lambda
│ ├── lambda_handler.zip
│ └── src
│ └── main_lambda.py
└── terragrunt.hcl
Modules (terraform codes) below:
├── apigw
│ ├── main.tf
│ └── variables.tf
└── lambda
├── main.tf
├── outputs.tf
--Output under lambda module
output "function_name" {
value = aws_lambda_function.auto-start.function_name
}
output "invoke_arn" {
value = aws_lambda_function.auto-start.invoke_arn
}
---------Error below when I run terragrunt run-all apply
╷
│ Error: Reference to undeclared resource
│
│ on main.tf line 59, in resource "aws_api_gateway_integration" "MyDemoIntegration":
│ 59: uri = aws_lambda_function.auto-start.invoke_arn
│
│ A managed resource "aws_lambda_function" "auto-start" has not been declared
│ in the root module.
╵
╷
│ Error: Reference to undeclared resource
│
│ on main.tf line 111, in resource "aws_lambda_permission" "api_gw":
│ 111: function_name = aws_lambda_function.auto-start.function_name
│
│ A managed resource "aws_lambda_function" "auto-start" has not been declared
│ in the root module.
My main.tf under apigw module look like this
Line 59 (uri)
resource "aws_api_gateway_integration" "MyDemoIntegration" {
rest_api_id = aws_api_gateway_rest_api.testAPI.id
resource_id = aws_api_gateway_resource.testresource.id
http_method = aws_api_gateway_method.testMethod.http_method
integration_http_method = "POST"
uri = aws_lambda_function.auto-start.invoke_arn
type = "AWS"
passthrough_behavior = "WHEN_NO_TEMPLATES"
tags = local.tags
}
Line 111 (function_name)
resource "aws_lambda_permission" "api_gw" {
statement_id = "AllowExecutionFromAPIGateway"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.auto-start.function_name
principal = "apigateway.amazonaws.com"
source_arn = "${aws_api_gateway_rest_api.testAPI.execution_arn}//"
tags = local.tags
}
NOW my terragrunt.hcl under apigw folder
dependencies {
paths = ["../lambda"]
}
dependency "lambda" {
config_path = "../lambda"
}
inputs = {
function_name = dependency.lambda.outputs.function_name
invoke_arn = dependency.lambda.outputs.invoke_arn
env = local.env
}
include {
path = find_in_parent_folders()
}
Tracked in ticket #110026
Beta Was this translation helpful? Give feedback.
All reactions