Terraform: archive_file keeps showing diff when using output_hash in aws_lambda_function

Created on 26 Aug 2016  ยท  8Comments  ยท  Source: hashicorp/terraform

Terraform Version

0.7.2

Affected Resource(s)

  • archive_file
  • aws_lambda_function

    Terraform Configuration Files

resource "template_file" "lambda" {
  template = "${file("${path.module}/templates/lambda.js.tpl")}"

  vars {
    environment = "${var.environment}"
    id = "${var.id}"
  }
}

resource "archive_file" "lambda" {
  type = "zip"
  source_content = "${template_file.lambda.rendered}"
  source_content_filename = "lambda.js"
  output_path = "${path.module}/lambda/lambda.zip"
}
resource "aws_lambda_function" "force_ebs_backup_lambda" {
  filename = "${archive_file.lambda.output_path}"
  source_code_hash = "${archive_file.lambda.output_sha}"
  ...
}

Update - It's the same with data sources based templates too.

Debug Output

terraform plan keeps showing that there is change in the source_code_hash of the lambda

Expected Behavior

Hash should not change with no change in content

Actual Behavior

terraform plan keeps showing that there is change in the source_code_hash of the lambda

bug provideaws

Most helpful comment

Closed vis #8492 - this will be released in Terraform 0.7.8

All 8 comments

/cc @BSick7

Somewhat related: #8492 works to migrate archive_file to datasource to prevent recreation in atlas.

I came here to file the same issue:
my understanding that archive_file.file.output_sha is generating SHA1, while Lambda expecting/providing SHA256.

archive_file.file.output_sha is generating SHA1, while Lambda expecting/providing SHA256.

Going through the code, I had come to the same realization. Calculating the sha256 as needed from the file instead of using the the output_sha as a workaround.

The fix #8492 to make archive_file a datasource includes an exported attribute output_base64sha256.

@BSick7 Awesome, good to know!

Closed vis #8492 - this will be released in Terraform 0.7.8

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings