我具有以下文件结构:
├── lambda
│ ├── main.tf
├── main.tf
main.tf
my_custom_lambda_function
从lambda
文件夹创建模块。
module "my_custom_lambda_function" {
source = "./lambda"
function_name = "some-name"
}
然后,我有一个嵌套模块,lambda
其中包含一个在线模块:
# lambda/main.tf
variable "function_name" {
type = string
}
module "lambda_template" {
source = "terraform-aws-modules/lambda/aws"
function_name = "{var.function_name}"
}
我需要访问模块的输出module.lambda_template
从module.my_custom_lambda_function
。但是,当我尝试这样做时:
# lambda/main.tf
output "function_arn" {
value = module.lambda_template.this_lambda_function_arn
}
我收到以下错误:
No module call named "lambda_function" is declared in the root module.
这是有道理的,因为此语法是指根目录中的模块。但是我想访问相对于我当前所在模块的模块。我尚未找到一种方法来执行此操作。就像是:
# lambda/main.tf
output "function_arn" {
value = module.${this}.module.lambda_function.this_lambda_function_arn
}
其中的价值this
是my_custom_lambda_function
。
这段代码不是有效的语法,但是它表达了我的需要。有没有办法在Terraform中做到这一点?
基于评论和聊天讨论。
我尝试复制该设置,但发现没有问题。一切都按预期工作。
现在它也适用于OP。在聊天讨论中,此问题可能之前是由模块或输出名称中的拼写错误引起的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句