Skip to content

source_code_hash of fastly_service_compute resource changes even if code doesn't #767

@marcoieni

Description

@marcoieni

The plan of the crates-io module is always dirty because of the resource fastly_service_compute. I.e. the command fastly compute build is not idempotent.

That's because:

  • fastly can add new features to the cli from time to time that change the content of the package
  • the fastly cli adds information about the build system

fastly_package_hash was an attempt to make the build more deterministic and it worked for a while, but now it doesn't work anymore.

How to reproduce

Run terragrunt plan in the directory terragrunt/accounts/legacy/crates-io-staging/crates-io.
The output is similar to:

Terraform will perform the following actions:
  # fastly_service_compute.static will be updated in-place
  ~ resource "fastly_service_compute" "static" {
      ~ active_version = 101 -> (known after apply)
      ~ cloned_version = 101 -> (known after apply)
        id             = "liljrvY3Xt0CzNk0mpuLa7"
        name           = "static.staging.crates.io"
        # (4 unchanged attributes hidden)
      ~ package {
          ~ source_code_hash = "bfb44cfc4b390d6223360587b1ed5b2ddf9ae544907b20d1e232854153f989d6f7f740d14a96a39a1efd0ab38948c73b294c11e4f065f0e1d1065036798e138d" -> "a5cc3df8ac067ebde8b86783eb0156d2de4727cdc85098f7aa48ff099f6da4d9469a5ae7a24dce42cbed504a970f613b543dd9ee9799ee7bfbe11be0c284a067"
            # (1 unchanged attribute hidden)
        }
        # (8 unchanged blocks hidden)
    }
Plan: 0 to add, 1 to change, 0 to destroy.

Possible fix

Here's what we need to do (roughly) to determine if the code changed:

  1. Decompress the file
  2. Diff the content to figure out what file changed (probably the wasm bundle)
  3. Decompile wasm file
  4. Read the binary to figure out what changed and determine if only metadata changed or if the source code changed and we need to redeploy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions