terraform - 不推荐使用 archive_file 作为资源

标签 terraform deprecation-warning

当我运行 terraform 脚本时收到此消息:

Warning: Deprecated Resource

using archive_file as a resource is deprecated; consider using the data source instead

问题是我该怎么做?我尝试阅读有关数据源的信息,但没有清除任何内容。

我在 lambda 定义中使用 archive_file 来压缩 lambda 源并获取目标 zip 哈希值。

resource "archive_file" "archive_csv_validate" {
  type        = "zip"
  source_dir  = "lambda/csv-validate"
  output_path = "artifacts/csv-validate.zip"
}

resource "aws_lambda_function" "lambda_csv_validate_function" {
  function_name    = "csv-validate"
  filename         = archive_file.archive_csv_validate.output_path
  source_code_hash = archive_file.archive_csv_validate.output_base64sha256
  handler          = "main.main"
  role             = aws_iam_role.lambda_iam_role.arn
  runtime          = "python3.9"
  timeout          = 900
}

最佳答案

Archive_file 现在是数据源。 您可以将代码转换为:

data "archive_file" "archive_csv_validate" {
  type        = "zip"
  source_dir  = "lambda/csv-validate"
  output_path = "artifacts/csv-validate.zip"
}

resource "aws_lambda_function" "lambda_csv_validate_function" {
  function_name    = "csv-validate"
  filename         = data.archive_file.archive_csv_validate.output_path
  source_code_hash = data.archive_file.archive_csv_validate.output_base64sha256
  handler          = "main.main"
  role             = aws_iam_role.lambda_iam_role.arn
  runtime          = "python3.9"
  timeout          = 900
}

关于terraform - 不推荐使用 archive_file 作为资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72888293/

相关文章:

azure - 如何使用 Terraform 将多个组添加到 Azure API 管理服务产品中?

android - 为什么不推荐使用 setDrawerListener 方法?如何解决?

python - 运行单元测试时没有弃用警告

eclipse - Groovy 不推荐使用的方法和 Eclipse - 排序

Terraform 的 Azure 虚拟机扩展文件 URL 位置

python - 使用 Python 以编程方式编辑 Terraform 配置文件

azure - 使用 terraform 创建 Data Lake Storage 表示 datalakestore.Client#GetProperties 即使它具有完全权限

terraform - API 网关日志未显示为 terraform

node.js - 弃用警告 : Listening to events on the Db class has been deprecated and will be removed in the next major version

regex - 已弃用 - Scala 正则表达式模式匹配