terraform-provider-archive
terraform-provider-archive copied to clipboard
difference between resource archive_file and data archive_file
Terraform Version
Terraform v0.12.24
- provider.archive v1.3.0
- provider.azurerm v2.7.0
- provider.local v1.4.0
- provider.null v2.1.2
- provider.random v2.2.1
Affected Resource(s)
Please list the resources as a list, for example:
- archive_file
Terraform Configuration Files
data "archive_file" "packs" {
depends_on = [
local_file.function]
for_each = var.configuratin_collection
output_path = "${path.module}/.pack_${each.key}.zip"
type = "zip"
source_dir = "${path.module}/.pack_${each.key}"
}
resource "null_resource" "pack_upload" {
for_each = var.configuratin_collection
triggers = {
archive_file = data.archive_file.packs[each.key].output_path
zip_hash = data.archive_file.packs[each.key].output_md5
}
provisioner "local-exec" {
command = <<COMMAND
....
COMMAND
}
}
Debug Output
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement
<= read (data resources)
Terraform will perform the following actions:
# module.azure_function.module.internal.data.archive_file.packs["test_function"] will be read during apply
# (config refers to values not yet known)
<= data "archive_file" "packs" {
+ id = (known after apply)
+ output_base64sha256 = (known after apply)
+ output_md5 = (known after apply)
+ output_path = "../ForEach/.pack_test_function.zip"
+ output_sha = (known after apply)
+ output_size = (known after apply)
+ source_dir = "../ForEach/.pack_test_function"
+ type = "zip"
}
# module.azure_function.module.internal.null_resource.pack_upload["test_function"] must be replaced
-/+ resource "null_resource" "pack_upload" {
~ id = "7158927369914622277" -> (known after apply)
~ triggers = {
- "archive_file" = "../ForEach/.pack_test_function.zip"
- "function_name" = "testfunction-de3i6si7h3"
- "resource_group" = "rg-azurefunctiontest"
- "subscription" = "1e1a42bf-00fd-4289-aba1-8a8898c8c12b"
- "zip_hash" = "67b5def34234d9b3c8059d6ce5a01b92"
} -> (known after apply) # forces replacement
}
Plan: 1 to add, 0 to change, 1 to destroy.
Expected Behavior
I was using the archive_file
resource until recently, and tried to fix the warning by replacing it with the datasource. But the datasource causes issues when using the ouputs of the archive as trigger in a custom resource.
When using resource archive_file archive
the null_resource is only redeployed when the content of the archive is changed. When using data archive_file archive
the null_resource is recreated every time.
Actual Behavior
The null_resource
should not get recreated if the content is not changed.
Steps to Reproduce
Please list the steps required to reproduce the issue, for example:
-
terraform plan
Any Updates ?