Terraform – error archiving file: could not archive missing file: ./RestoreDynamoDbFromS3.py

I'm trying to zip a python file and use that inside a lambda function in terraform. My terraform code looks like -

data archive_file RestoreDynamoDbFromS3 {
  type        = "zip"
  source_file = "${path.module}/RestoreDynamoDbFromS3.py"
  output_path = "${path.module}/RestoreDynamoDbFromS3.zip"
}

resource aws_lambda_function account_restore_ledgersummary_from_s3 {
  function_name    = "${var.environment_id}-AccountService-${var.account_ledgersummary_restore_event_handler["namespace"]}"
  runtime          = "python3.7"
  handler          = "RestoreDynamoDbFromS3.lambda_handler"
  role             = aws_iam_role.account_s3_to_dynamodb_lambda_role.arn
  filename         = data.archive_file.RestoreDynamoDbFromS3.output_path
  source_code_hash = filebase64sha256(data.archive_file.RestoreDynamoDbFromS3.output_path)

  environment {
    variables = {
      ENVIRONMENT = var.environment_id
    }
  }

  # Tags defined in locals only.
  tags = local.common_tags
}

My python script and tf file are in the same directory, am I doing something wrong here? I'm getting below error


2021-04-08T13:10:48.9114701Z ##[error][31m
2021-04-08T13:10:48.9115778Z ##[error][1m[31mError: [0m[0m[1merror archiving file: could not archive missing file: ./RestoreDynamoDbFromS3.py[0m
2021-04-08T13:10:48.9116766Z ##[error][0m[0m[0m
2021-04-08T13:10:49.0449821Z ##[error]Failed to plan configuration for workspace mahbis01, version 2.0.0-abranch.251640: Cake.Core.CakeException: Terraform: Process returned an error (exit code 1).
2021-04-08T13:10:49.0451956Z ##[error]   at Cake.Core.Tooling.Tool`1.ProcessExitCode(Int32 exitCode)
2021-04-08T13:10:49.0453490Z ##[error]   at Cake.Core.Tooling.Tool`1.Run(TSettings settings, ProcessArgumentBuilder arguments, ProcessSettings processSettings, Action`1 postAction)
2021-04-08T13:10:49.0454667Z ##[error]   at Cake.Terraform.TerraformPlanRunner.Run(TerraformPlanSettings settings)
2021-04-08T13:10:49.0455645Z ##[error]   at Submission#0.PlanConfiguration(String env, String ver)
2021-04-08T13:10:49.0464023Z ##[error]An error occurred when executing task 'Deploy'.
2021-04-08T13:10:49.0515820Z ##[error]Error: One or more errors occurred.
2021-04-08T13:10:49.0517449Z ##[error]  Terraform: Process returned an error (exit code 1).
2021-04-08T13:10:49.0932930Z ##[error]System.Exception: Unexpected exit code 1 returned from tool Cake.exe
2021-04-08T13:10:49.0934551Z    at Microsoft.TeamFoundation.DistributedTask.Task.Internal.InvokeToolCmdlet.ProcessRecord()
2021-04-08T13:10:49.0935335Z    at System.Management.Automation.CommandProcessor.ProcessRecord()
2021-04-08T13:10:49.1142347Z ##[error]PowerShell script completed with 1 errors.


Read more here: https://stackoverflow.com/questions/67004815/terraform-error-archiving-file-could-not-archive-missing-file-restoredynam

Content Attribution

This content was originally published by Biswajit Maharana at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: