serverless (function/container/namespace): import resources with secret environment variables #2382
Labels
container
Container issues, bugs and feature requests
enhancement
function
Serverless function issues, bugs and feature requests
priority:high
New features
Community Note
Context
We can't really import serverless resources (namespaces, functions, containers) who have secret environment variables. By their nature, secret environment variables are sensitive, and therefore, not returned in plain text when
GET
ting the resource.However, a value hashed with Argon2id algorithm is returned by the API (see for example the documentation for functions):
Sadly, instead of leveraging this hashed value, the current implementation of the Terraform provider discards the secret environment variables: after importing a resource, the
secret_environment_variables
field will always benull
.This is unfortunate, as running
terraform import
followed byterraform apply
will redeploy the resource, assecret_environment_variables
changed fromnull
to a non-null
value. Thus, it will always trigger an unnecessary deployment, in the case offunction
andcontainer
. Or even worse, in thenamespace
case, as updating secrets of a namespace will redeploy all functions/containers inside.After the first
apply
and the "unnecessary" redeployment, the secret environment variables will be stored in the state, so the nextapply
operations will behave correctly though, because now the variables are stored in the state. However, another issue is that these variables values are stored in plain text in the state, while we can technically reuse the hashed value to compare, and this would simplify managing the secrets in theimport
case.Description
We could actually solve both issues (
import
does not set secrets + secrets values stored in plain text in the state) at the same time:secret_environment_variables
field with the values returned by the APIComparePasswordAndHash
method to decide if one of the values has changed. If a single value of a secret has changed, we can update the secrets; if not, we don't have to updateI don't think that changing the state internal values is a breaking change (but I might be wrong).
New or Affected Resource(s)
scaleway_function_namespace
scaleway_function
scaleway_container_namespace
scaleway_container
Potential Terraform Configuration
Experience should be the same as today.
The text was updated successfully, but these errors were encountered: