简体   繁体   English

terraform 将资源 ID 检索到变量中,以用于创建带有环境变量的 lambda

[英]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.

相关问题 将 terraform 中的“公共变量”重新用于 Lambda 环境变量 - Re-use "common variables" in terraform for Lambda environment variables 更新 lambda 环境变量(由 terraform 生成) - Update lambda environment variables (generated by terraform) 在 Dockerfile 或通过 terraform 设置 $_HANDLER 环境变量 AWS Lambda - Set $_HANDLER environment variable AWS Lambda in Dockerfile or via terraform 如何使用 Terraform 将值列表传递到 Lambda 环境变量 - How to pass a list of values into Lambda environment variables with Terraform Terraform模板中的资源创建顺序 - Order of resource creation in Terraform template terraform:在 google_cloudfunctions_function 资源中添加“secret_environment_variables”时出错 - terraform: Error while adding "secret_environment_variables" in google_cloudfunctions_function resource 如果变量不是 null,则创建 Terraform 资源 - Create Terraform resource if variable is not null 从 terraform 中的变量引用资源 - Reference resource from variable in terraform Terraform - 如何将环境变量传递给 terraform 中的子模块 - Terraform - How to pass environment variables to sub modules in terraform AWS Codebuild 中的多个环境变量与 Terraform - Multiple Environment Variables in AWS Codebuild with Terraform
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM