简体   繁体   中英

Terraform aws_s3_bucket_object not triggered by archive_file

I have built the following terraform code:

data "archive_file" "lambda_dependencies_bundle" {
  depends_on = [
    null_resource.lambda_dependencies
  ]

  output_path = "${local.function_build_folder_path}/build/${local.function_s3_object_key}.zip"
  excludes    = ["${local.function_build_folder_path}/build/*"]
  source_dir  = local.function_build_folder_path
  type        = "zip"
}

resource "aws_s3_bucket" "lambda_dependencies_bucket" {
  bucket = local.function_s3_bucket
  acl    = "private"
}

resource "aws_s3_bucket_object" "lambda_dependencies_upload" {
  bucket = aws_s3_bucket.lambda_dependencies_bucket.id
  key    = "${local.function_s3_object_key}.zip"
  source = data.archive_file.lambda_dependencies_bundle.output_path
}

The null_resource.lambda_dependencies is triggered by a file change and just builds all of my code to local.function_build_folder_path . Everytime the null_resource changes, the archive_file.lambda_dependencies_bundle rebuilds (correct behavior.).

But other than expected, the aws_s3_bucket_object.lambda_dependencies_upload is not triggered by the rebuild of the archive_file.

How can I achieve a reupload of my archive_file on a rebuild?

I would add etag :

Triggers updates when the value changes.

resource "aws_s3_bucket_object" "lambda_dependencies_upload" {
  bucket = aws_s3_bucket.lambda_dependencies_bucket.id
  key    = "${local.function_s3_object_key}.zip"
  source = data.archive_file.lambda_dependencies_bundle.output_path
  etag = data.archive_file.lambda_dependencies_bundle.output_md5
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM