使用Archive_file作为资源

发布于 2025-02-13 11:42:15 字数 844 浏览 1 评论 0原文

当我运行Terraform脚本时,我收到了此消息:

Warning: Deprecated Resource

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

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

我在lambda定义中使用Archive_file来zing我的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
}

I got this message when I run my terraform script:

Warning: Deprecated Resource

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

The question is how should I do this? I tried to read about the data source, but it didn't clear anything.

I use archive_file in lambda definition for zipping my lambda source and getting target zip hash.

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
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

永不分离 2025-02-20 11:42:15

现在,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
}

Archive_file is now a data source.
You can transform your code as this:

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
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文