puppetlabs/puppetlabs-mysql

Mysql::Db parameter 'tls_options' expects a value of type Undef or Array, got String

alexbugl opened this issue · 3 comments

Describe the Bug

After update of v13.1.0 to v13.2.0 of the puppetlabs-mysql module we get the following error:

Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Mysql::Db[icinga2]:
parameter 'tls_options' expects a value of type Undef or Array, got String (file: /etc/puppetlabs/code/environments/dev/modules/icinga/manifests/database.pp, line: 94) on node X

Expected Behavior

In version v13.2.0 you added the type Optional[Array[String[1]]] to the parameter tls_options, which breaks one of the modules we use (puppet-icinga) -- this tries to create a MySQL DB using this code:

    $_tls_options = if $tls {
      if $tls =~ String and $tls == 'cert' {
        'X509'
      } else {
        'SSL'
      }
    } else {
      'NONE'
    }

    mysql::db { $db_name:
      tls_options => $_tls_options,
      # shortened for readability
    }

So it writes a string into attribute tls_options of type mysql::db, which does not match the associated type.
But your code in lib/puppet/type/mysql_user.rb seems to still be able to cope with strings, as it creates an array out of a single string:

  newproperty(:tls_options, array_matching: :all) do
    desc 'Options to that set the TLS-related REQUIRE attributes for the user.'
    validate do |value|
      value = [value] unless value.is_a?(Array)
      if value.include?('NONE') || value.include?('SSL') || value.include?('X509')

Environment

  • Module Version v13.2.0
  • Platform Debian 11

Suggested Solution

A possible solution could be to correct the type (untested at the moment):

-Optional[Array[String[1]]]                     $tls_options     = undef,
+Optional[Variant[String[1], Array[String[1]]]] $tls_options     = undef,

To maybe speed a bugfix up a bit, I've created a pull request #1540 based on Alex suggestion.

I tested the fix, and it really solved the bug. :)
Please apply ...

I've updated the pull request to the current main. Would be really nice to get the bugfix in, unfortunately the fix didn't make it into v13.3.0.