Chris Cynarski
Chris Cynarski

Reputation: 513

Using archive_file as a resource is deprecated

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
}

Upvotes: 3

Views: 8796

Answers (1)

Marouan B
Marouan B

Reputation: 96

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
}

Upvotes: 7

Related Questions