tpretz / terraform-provider-zabbix

Terraform Zabbix Provider
MIT License
30 stars 27 forks source link

Preprocessor multiline parameters issue #15

Open vicioussn opened 2 years ago

vicioussn commented 2 years ago

Hello!

If you provide multiline preprocessor parameter, apply will want to re-apply the code.

Here is the code piece:

preprocessor {
    type = "21"
    params = [ "var newvalue;\nswitch(JSON.parse(value)[0]) {\n  case \"up\":\n    newvalue = 1;\n    break;\n  case \"down\":\n    newvalue = 2;\n    break;\n  case \"testing\":\n    newvalue = 4;\n    break;\n  case \"unknown\":\n    newvalue = 5;\n    break;\n  case \"dormant\":\n    newvalue = 6;\n    break;\n  case \"notPresent\":\n    newvalue = 7;\n    break;\n  default:\n    newvalue = \"Problem parsing interface operstate in JS\";\n}\nreturn newvalue;",  ]
    error_handler = "0"
  }

Here is what it want to change:

~ preprocessor {
          ~ params        = [
              - "var newvalue;",
              - "switch(JSON.parse(value)[0]) {",
              - "  case \"up\":",
              - "    newvalue = 1;",
              - "    break;",
              - "  case \"down\":",
              - "    newvalue = 2;",
              - "    break;",
              - "  case \"testing\":",
              - "    newvalue = 4;",
              - "    break;",
              - "  case \"unknown\":",
              - "    newvalue = 5;",
              - "    break;",
              - "  case \"dormant\":",
              - "    newvalue = 6;",
              - "    break;",
              - "  case \"notPresent\":",
              - "    newvalue = 7;",
              - "    break;",
              - "  default:",
              - "    newvalue = \"Problem parsing interface operstate in JS\";",
              - "}",
              - "return newvalue;",
              + <<-EOT
                    var newvalue;
                    switch(JSON.parse(value)[0]) {
                      case "up":
                        newvalue = 1;
                        break;
                      case "down":
                        newvalue = 2;
                        break;
                      case "testing":
                        newvalue = 4;
                        break;
                      case "unknown":
                        newvalue = 5;
                        break;
                      case "dormant":
                        newvalue = 6;
                        break;
                      case "notPresent":
                        newvalue = 7;
                        break;
                      default:
                        newvalue = "Problem parsing interface operstate in JS";
                    }
                    return newvalue;
                EOT,
            ]
            # (2 unchanged attributes hidden)
        }
tpretz commented 2 years ago

Hi,

params is a list of strings, made for the older preprocessors which took a handful of distinct arguments (and under the hood it was combined with newline characters to form one string)

as a side effect, for javascript it still expects a list of strings (and internally splits / joins)

Try doing similar to https://github.com/tpretz/terraform-provider-zabbix/blob/a9d578dd02846b7c2085c6da861f74716a18a351/provider/resource_item_agent_test.go#L263

See if that helps

vicioussn commented 2 years ago

Hi!

Yep thanks, will try in 1-2-3 weeks!