scaleway / terraform-provider-scaleway

Terraform Scaleway provider
https://www.terraform.io/docs/providers/scaleway/
Mozilla Public License 2.0
199 stars 123 forks source link

secret: add different formats #1957

Open Codelax opened 1 year ago

Codelax commented 1 year ago

This present an idea to improve secret api by adding new fields.

The first one would be adding a base64 field to allow uploading files or anything that is not valid utf-8

resource scaleway_secret_version version {
  data = "string"
  data_base64 = "base64encoded_string"
}

For the datasource, we could add a type field that default to base64.

data scaleway_secret_version version_base64 {
  # type = "base64"
  # data = "base64"
}

data scaleway_secret_version version_base64 {
  type = "string"
  # data = "valid string"
}
jgalais commented 4 months ago

Hello,

I had the same problem today. I have multiple passwords.

If i check my password 3 passwords are encoded in base64 and 3 not.

It seems that if the password have no special char in this case "scaleway_secret_version" send the password without base64 encoding.

output "password_test" {
  value = [ for password in [ 
  local.secret_fields_information["password1"].data,
  local.secret_fields_information["password2"].data,
  local.secret_fields_information["password3"].data,
  local.secret_fields_information["password4"].data,
  local.secret_fields_information["password5"].data,
  local.secret_fields_information["password6"].data
   ] : password]
}

Output:

  + password_test = [
      + "BASE64ENCODED",                # Special char inside password
      + "NOBASE64ENCODED",          # No special char inside password
      + "NOBASE64ENCODED",          # No special char inside password
      + "NOBASE64ENCODED",          # No special char inside password
      + "BASE64ENCODED",                # Special char inside password
      + "BASE64ENCODED",                # Special char inside password
    ]

For Terraform error "the result of decoding the provided string is not valid UTF-8.":

╷
│ Error: Error in function call
│ Call to function "base64decode" failed: the result of decoding the provided string is not valid UTF-8.

This error is present because Terraform wants to have base64 encoded text but the text is on clear. It's just a side effect of scaleway_secret_version problem. If the resource "scaleway_secret_version" is fixed your error will disappear.

The solution i think is to convert in base64 all passwords even if no special char is present to avoid different behaviors.

Regards,