[英]terraform retrieve resource id into variable to use in creation of lambda with environment variables
I am trying to use terraform to standup aws cognito, and dynamically pass some output value of the created resource as environment variables to a lambda resource that terraform will also create.我正在尝试使用 terraform 来支持 aws cognito,并将创建的资源的一些 output 值作为环境变量动态传递给 terraform 也将创建的 lambda 资源。
I have a lambda function that handles authentication with cognito, and requires the cognito client app id and client app secret to function.我有一个 lambda function,它使用 cognito 处理身份验证,需要 function 的 cognito 客户端应用程序 ID 和客户端应用程序密码。
Wondering if there is a way to get this metadata within terraform and reference it when the lambda resource gets created.想知道是否有办法在 terraform 中获取此元数据并在创建 lambda 资源时引用它。
The Terraform aws_cognito_user_pool_client
resource, which you will use to create the Cognito user pool client via Terraform, has those values you mention as outputs . Terraform aws_cognito_user_pool_client
资源,您将使用它通过 Terraform 创建 Cognito 用户池客户端, 具有您提到的那些值作为输出。 All you need to do is reference those values in your Lambda resource.您需要做的就是在 Lambda 资源中引用这些值。 Like so:像这样:
resource "aws_cognito_user_pool_client" "my_app_client" {
...
}
resource "aws_lambda_function" "my_lambda_function" {
...
environment {
variables = {
"COGNITO_CLIENT_ID" = aws_cognito_user_pool_client.my_app_client.id,
"COGNITO_CLIENT_SECRET" = aws_cognito_user_pool_client.my_app_client.client_secret
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.