问题描述
我正在尝试定义一个返回Lambda函数的ARN的地形输出块.Lambda在子模块中定义.根据文档,lambda似乎应该已经具有ARN属性: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/lambda_function#arn
I am trying to define a terraform output block that returns the ARN of a Lambda function. The Lambda is defined in a sub-module. According to the documentation it seems like the lambda should just have an ARN attribute already: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/lambda_function#arn
使用它作为来源,我认为我应该能够执行以下操作:
Using that as a source I thought I should be able to do the following:
output "lambda_arn" {
value = module.aws_lambda_function.arn
}
这会产生以下错误:
Error: Unsupported attribute
on main.tf line 19, in output "lambda_arn":
19: value = module.aws_lambda_function.arn
This object does not have an attribute named "arn".
谢谢您的投入.
推荐答案
文档正确.数据源 data.aws_lambda_function
具有 arn
属性.但是,您试图从自定义模块 module.aws_lambda_function
访问 arn
.为此,您必须在模块中定义输出 arn
.
Documentation is correct. Data source data.aws_lambda_function
has arn
attribute. However, you are trying to access the arn
from a custom module module.aws_lambda_function
. To do this you have to define output arn
in your module.
因此,在您的模块中,您应该具有以下内容:
So in your module you should have something like this:
data "aws_lambda_function" "existing" {
function_name = "function-to-get"
}
output "arn" {
value = data.aws_lambda_function.existing.arn
}
然后,如果您的模块名为 aws_lambda_function
:
Then if you have your module called aws_lambda_function
:
module "aws_lambda_function" {
source = "path-to-module"
}
您将能够访问 arn
:
module.aws_lambda_function.arn
这篇关于如何使用Terraform获取AWS Lambda ARN?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!