Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

difference between resource archive_file and data archive_file #69

Open
raphaelschnaitl opened this issue Apr 30, 2020 · 1 comment
Open

Comments

@raphaelschnaitl
Copy link

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:

  1. terraform plan
@raphaelschnaitl
Copy link
Author

Any Updates ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant