function: replace zip_hash with internal logic to see if zips differ #2383
Labels
enhancement
function
Serverless function issues, bugs and feature requests
priority:medium
Improvements that are not the main priority
Community Note
Context
As of today, we rely on the
scaleway_function
'szip_hash
field and let the user handle the logic if the function code has changed or not (see documentation).While this is very useful to avoid redeploying the function if the zip has not changed (if
zip_hash
is the same as the one in the state, don't redeploy), it adds extra logic that is not really something the user wants to manage.Also, this logic makes it impossible to
import
afunction
, as thezip_hash
set byterraform import
will always benull
. As a result, runningterraform apply
after aterraform import
will always trigger a function deployment, even if the zip is exactly the same (but, it's normal, since Terraform has no way to see if the zip matches).Description
For both reasons described above (degraded UX + import does not work), my proposition is to remove the
zip_hash
field.Instead, we can leverage the fact a hash and the size of the zip can be found using the s3 download URL returned by the API.
Example (shell):
The last call aims to retrieve
content-range
andetag
fields (s3 common fields), to respectively find the size of the zip (here,347
) and the md5 sum (here,09d5c064f79f0eddc012c6d3cf8d35f9
). Note that we can't send aHEAD
request to the download URL of a function, so we have to trick here with-X GET -r 0-0
to get those fields.To check if the zip has changed, we just have to check if these 2 fields of the local zip matches the ones for the remote zip. While the hash can be enough, we can also decide to the size of the zip to mitigate md5 algorithm weaknesses. Even if it's very unlikely that a user creates a new zip with the exact md5 sum of the old one! Anyway, computing a md5 hash or retrieving the size of a local file is something that can be done pretty quickly in Go.
New or Affected Resource(s)
scaleway_function
Potential Terraform Configuration
We don't need
zip_hash
field anymore. Terraform provider will detect automatically if the zip differs from the existing one.The text was updated successfully, but these errors were encountered: