Amazon web services 在terraform中的嵌套模块中引用变量

Amazon web services 在terraform中的嵌套模块中引用变量,amazon-web-services,aws-lambda,terraform,amazon-cognito,Amazon Web Services,Aws Lambda,Terraform,Amazon Cognito,我正在使用terraform开发用于用户池身份验证的lambda授权程序,我需要动态设置环境变量,从src>modules>application services>modules>application service>variables.tf到src>modules>lambda auth>variables.tf。我不知道如何引用它,我已经在outputs.tf中为application services>modules>application service>variables.tf声明

我正在使用terraform开发用于用户池身份验证的lambda授权程序,我需要动态设置环境变量,从
src>modules>application services>modules>application service>variables.tf
src>modules>lambda auth>variables.tf
。我不知道如何引用它,我已经在outputs.tf中为
application services>modules>application service>variables.tf声明了它们。这是我的文件结构

You can't reference values directly from one module to another at all. The level where the 
module
is declared is the only level that has access to the module's outputs. To pass those values to other levels you have to declare the value as an output of the
application-services
module also, which will make it available in
main
. Then declare an input variable for the
lambda
module, and have
main
pass the value into the
lambda
module.


application-services/outputs.tf

output "user-pool-id" {
  value = module.application-service.user-pool-id
}

您根本无法将值直接从一个模块引用到另一个模块。声明模块
的级别是唯一可以访问模块输出的级别。要将这些值传递到其他级别,您还必须将该值声明为
应用程序服务
模块的输出,这将使其在
main
中可用。然后为
lambda
模块声明一个输入变量,并让
main
将该值传递到
lambda
模块中


应用程序服务/输出。tf

module "lambda-auth" {
  source = "lambda-auth"

  prod_userpoolid = module.application-services.user-pool-id
}
main.tf

module "lambda-auth" {
  source = "lambda-auth"

  prod_userpoolid = module.application-services.user-pool-id
}

我已经在outputs.tf中声明了变量,这在理论上意味着我应该能够在lambda.tf中使用它,但是最后一部分,您说我需要“为lambda模块声明一个输入变量,并让main将值传递到lambda模块”。我该怎么做呢。感谢您的帮助。不,您在
应用程序服务
的outputs.tf中声明了它,这意味着它当前在
应用程序服务
中可用,而在其他任何地方都不可用。您缺少子模块的输出仅对调用模块可用的部分。您首先需要将outputs.tf添加到
application services
,然后从那里再次输出值,这将使其在
main
中可用。然后,您需要将其作为输入传递给
lambda
,就像您已经将其他输入传递给
lambda
@figuring一样。请参见我添加到回答中的代码示例。很抱歉,这又是一个初学者问题,但我已经在“应用程序服务”下创建了outputs.tf文件,但我不确定如何声明它,它应该与“应用程序服务”outputs.tf中的代码相同。lambda.tf中声明的变量是变量的映射,这也会影响代码。@请看我的更新答案,我给了您需要添加到outputs.tf文件中的确切代码。