dmacvicar / terraform-provider-salt

"Logical" provider for integrating with salt-ssh roster module
Mozilla Public License 2.0
31 stars 9 forks source link

problem with "minion_opts" option #5

Open djooberlee opened 7 months ago

djooberlee commented 7 months ago

here is the resource

resource "salt_host" "roster" {

...

   minion_opts = {
     grains = jsonencode({
       example_grain = "value",
       another_grain = "another value"
     })
   }
}

in the terraform.tfstate file it looks like this

             "minion_opts": {
               "grains": "{\"another_grain\": \"another value\", \"example_grain\": \"value\"}"
             },

and in execution salt-ssh my_hostname grains.items I get an error

my_hostname:
     ----------
     _error:
         Failed to return clean data
     retcode:
         64
     stderr:
         Usage: salt-call [options] <function> [arguments]

         salt-call: error: Error while processing <function LogLevelMixIn.__setup_logging at 0x7f59a3683c10>: Traceback (most recent call last):
           File "/var/tmp/.root_9bf6da_salt/pyall/salt/utils/parsers.py", line 212, in parse_args
             mixin_after_parsed_func(self)
           File "/var/tmp/.root_9bf6da_salt/pyall/salt/utils/parsers.py", line 911, in __setup_logging
             salt._logging.setup_logging()
           File "/var/tmp/.root_9bf6da_salt/pyall/salt/_logging/impl.py", line 971, in setup_logging
             setup_extended_logging(opts)
           File "/var/tmp/.root_9bf6da_salt/pyall/salt/_logging/impl.py", line 878, in setup_extended_logging
             providers = salt.loader.log_handlers(opts)
           File "/var/tmp/.root_9bf6da_salt/pyall/salt/loader/__init__.py", line 860, in log_handlers
             ret = LazyLoader(
           File "/var/tmp/.root_9bf6da_salt/pyall/salt/loader/lazy.py", line 270, in __init__
             self.opts = self.__prep_mod_opts(opts)
           File "/var/tmp/.root_9bf6da_salt/pyall/salt/loader/lazy.py", line 588, in __prep_mod_opts
             self.pack["__grains__"] = salt.utils.context.NamespacedDictWrapper(
           File "/var/tmp/.root_9bf6da_salt/pyall/salt/utils/context.py", line 203, in __init__
             super().__init__(self._dict())
         ValueError: dictionary update sequence element #0 has length 1; 2 is required
     stdout:

but if changed in the terraform.tfstate file

             "minion_opts": {
               "grains": "{\"another_grain\":\"another value\",\"example_grain\":\"value\"}"
             },

as follows

             "minion_opts": {
               "grains": {"another_grain": "another value", "example_grain":"value"}
             },

then salt-ssh my_hostname grains.items works without errors

djooberlee commented 7 months ago

currently i fix it with liner

terraform state pull | jq '(.resources[] | select(.name == "roster") | .instances[].attributes.minion_opts.grains) |= fromjson' > terraform.tfstate