claranet / terraform-provider-zabbix

Terraform provider for Zabbix.
MIT License
29 stars 18 forks source link

Fix compatibility with zabbix 5 #17

Open barbaluc opened 4 years ago

barbaluc commented 4 years ago

Steps to reproduce

Write exemple.tf

resource "zabbix_host" "host" {
  host = "testzabbix"

  interfaces {
    dns  = "testzabbix.mydomain.local"
    main = true
  }
  interfaces {
    type = "jmx"
    dns  = "testzabbix.mydomain.local"
    main = true
    port = 50000
  }
  interfaces {
    type = "snmp"
    dns  = "testzabbix.mydomain.local"
    main = true
    port = 161
  }
  interfaces {
    type = "ipmi"
    dns  = "testzabbix.mydomain.local"
    main = true
    port = 623
  }

  groups    = []
  templates = []

  lifecycle {
    ignore_changes = [
      groups,
      templates,
    ]
  }
}

Write terraform.tf (Server must be in version 5)

provider "zabbix" {
  server_url = "https://prodzabbix.ouest-france.fr/api_jsonrpc.php"
  user           = "user"
  password   = "password"
}

Execute

terraform apply

Output error

zabbix_host.host: Creating...
2020/07/03 16:50:49 [DEBUG] zabbix_host.host: applying the planned Create change
2020/07/03 16:50:49 [TRACE] GRPCProvider: ApplyResourceChange
2020-07-03T16:50:49.016+0200 [DEBUG] plugin.terraform-provider-zabbix_v0.0.4: 2020/07/03 16:50:49 Groups []
2020/07/03 16:50:49 [DEBUG] zabbix_host.host: apply errored, but we're indicating that via the Error pointer rather than returning it: -32602 (Invalid params.): Incorrect arguments passed to function.
2020/07/03 16:50:49 [TRACE] <root>: eval: *terraform.EvalMaybeTainted
2020/07/03 16:50:49 [TRACE] EvalMaybeTainted: zabbix_host.host encountered an error during creation, so it is now marked as tainted
2020/07/03 16:50:49 [TRACE] <root>: eval: *terraform.EvalWriteState
2020/07/03 16:50:49 [TRACE] EvalWriteState: removing state object for zabbix_host.host
2020/07/03 16:50:49 [TRACE] <root>: eval: *terraform.EvalApplyProvisioners
2020/07/03 16:50:49 [TRACE] EvalApplyProvisioners: zabbix_host.host has no state, so skipping provisioners
2020/07/03 16:50:49 [TRACE] <root>: eval: *terraform.EvalMaybeTainted
2020/07/03 16:50:49 [TRACE] EvalMaybeTainted: zabbix_host.host encountered an error during creation, so it is now marked as tainted
2020/07/03 16:50:49 [TRACE] <root>: eval: *terraform.EvalWriteState
2020/07/03 16:50:49 [TRACE] EvalWriteState: removing state object for zabbix_host.host
2020/07/03 16:50:49 [TRACE] <root>: eval: *terraform.EvalIf
2020/07/03 16:50:49 [TRACE] <root>: eval: *terraform.EvalIf
2020/07/03 16:50:49 [TRACE] <root>: eval: *terraform.EvalWriteDiff
2020/07/03 16:50:49 [TRACE] <root>: eval: *terraform.EvalApplyPost
2020/07/03 16:50:49 [ERROR] <root>: eval: *terraform.EvalApplyPost, err: -32602 (Invalid params.): Incorrect arguments passed to function.
2020/07/03 16:50:49 [ERROR] <root>: eval: *terraform.EvalSequence, err: -32602 (Invalid params.): Incorrect arguments passed to function.
2020/07/03 16:50:49 [TRACE] [walkApply] Exiting eval tree: zabbix_host.host
2020/07/03 16:50:49 [TRACE] vertex "zabbix_host.host": visit complete
2020/07/03 16:50:49 [TRACE] dag/walk: upstream of "provider.zabbix (close)" errored, so skipping
2020/07/03 16:50:49 [TRACE] dag/walk: upstream of "meta.count-boundary (EachMode fixup)" errored, so skipping
2020/07/03 16:50:49 [TRACE] dag/walk: upstream of "root" errored, so skipping
2020/07/03 16:50:49 [TRACE] statemgr.Filesystem: creating backup snapshot at terraform.tfstate.backup
2020/07/03 16:50:49 [TRACE] statemgr.Filesystem: state has changed since last snapshot, so incrementing serial to 9
2020/07/03 16:50:49 [TRACE] statemgr.Filesystem: writing snapshot at terraform.tfstate
2020/07/03 16:50:49 [TRACE] statemgr.Filesystem: removing lock metadata file .terraform.tfstate.lock.info

2020/07/03 16:50:49 [TRACE] statemgr.Filesystem: unlocking terraform.tfstate using fcntl flock
Error: -32602 (Invalid params.): Incorrect arguments passed to function.

  on zabbix.tf line 1, in resource "zabbix_host" "host":
   1: resource "zabbix_host" "host" {

Thanks in advance for your help

pdecat commented 4 years ago

Hi @barbaluc, the issue is caused by the snmp block:

  interfaces {
    type = "snmp"
    dns  = "testzabbix.mydomain.local"
    main = true
    port = 161
  }

Commenting it out let's the apply work.

Zabbix 5.0 introduced a new details parameter that is required with SNMP interfaces:

details | array | Additional object for interface. Required if interface 'type' is SNMP.

See https://www.zabbix.com/documentation/5.0/manual/api/reference/hostinterface/object

The zabbix provider does not support that parameter yet, code changes need to be implemented.

barbaluc commented 4 years ago

Thanks @pdecat for your analyse. For starting, we will comment the snmp block, it's not completly necessary for our supervision.