Giter Site home page Giter Site logo

oxa-test / terraform-provider-zabbix Goto Github PK

View Code? Open in Web Editor NEW

This project forked from claranet/terraform-provider-zabbix

0.0 1.0 0.0 18.44 MB

Terraform provider for Zabbix.

License: MIT License

Makefile 0.26% Go 97.91% Shell 0.41% HTML 1.43%

terraform-provider-zabbix's Introduction

Build Status

Terraform Provider for Zabbix

Requirements

  • Terraform 0.12.x
  • Go 1.12 (to build the provider plugin)

Building The Provider

Clone repository to: $GOPATH/src/github.com/claranet/terraform-provider-zabbix

$ mkdir -p $GOPATH/src/github.com/claranet; cd $GOPATH/src/github.com/claranet
$ git clone [email protected]:claranet/terraform-provider-zabbix

Enter the provider directory and build the provider

$ cd $GOPATH/src/github.com/claranet/terraform-provider-zabbix
$ make build

Note: For contributions created from forks, the repository should still be cloned under the $GOPATH/src/github.com/claranet/terraform-provider-zabbix directory to allow the provided make commands to properly run, build, and test this project.

Using the provider

If you're building the provider, follow the instructions to install it as a plugin. After placing it into your plugins directory, run terraform init to initialize it.

Further usage documentation is available on the Terraform website.

Developing the Provider

If you wish to work on the provider, you'll first need Go installed on your machine (version 1.11+ is required). You'll also need to correctly setup a GOPATH, as well as adding $GOPATH/bin to your $PATH.

To compile the provider, run make build. This will build the provider and put the provider binary in the $GOPATH/bin directory.

$ make build
...
$ $GOPATH/bin/terraform-provider-zabbix
...

In order to test the provider, you can simply run make test.

$ make test

In order to run the full suite of Acceptance tests, run make testacc.

Note: Acceptance tests create real resources.

$ make testacc

Notes

Template linking

Template linking is used as a way to track template items and triggers in an authoritative way. A template link resource must contain all the ids of your local items and triggers otherwise they will be deleted during the next apply.

  • If you use the template link resource to track template dependencies you should pay attention to always have your local item and trigger referenced otherwise they will be deleted and will need to be recreated, causing a permanent diff.
  • If you have template dependencies you should use the template_id value of the zabbix_template_link resource to link the children templates to the parent else the child template could be updated before parent item or trigger which lead to errors like Error: Expected to delete 2 trigger and 1 were delete.

Examples

Host

provider "zabbix" {
  user = "Admin"
  password = "zabbix"
  server_url = "http://localhost/api_jsonrpc.php"
}

resource "zabbix_host" "zabbix1" {
  host = "127.0.0.1"
  name = "the best name"
  interfaces {
    ip = "127.0.0.1"
    main = true
  }
  groups = ["Linux servers", "${zabbix_host_group.zabbix.name}"]
  templates = ["Template ICMP Ping"]
}

resource "zabbix_host_group" "zabbix" {
  name = "something"
}

Template

The template link resource is required if you want to track your template item and trigger in an authoritative way.

provider "zabbix" {
  user = "Admin"
  password = "zabbix"
  server_url = "http://localhost/api_jsonrpc.php"
}

resource "zabbix_host_group" "demo_group" {
  name = "Template demo group"
}

resource "zabbix_template" "demo_template" {
  host        = "template"
  name        = "template demo"
  description = "An exemple of template with item and trigger"
  groups      = [zabbix_host_group.demo_group.name]
  macro = {
    MACRO_TEMPLATE = "12"
  }
}

# This virtual resource is responsible of ensuring no item and trigger is directly associated to the template
resource "zabbix_template_link" "demo_template_link" {
  template_id = zabbix_template.demo_template.id
}

Template with item and trigger

provider "zabbix" {
  user = "Admin"
  password = "zabbix"
  server_url = "http://localhost/api_jsonrpc.php"
}

resource "zabbix_host_group" "demo_group" {
  name = "Template demo group"
}

resource "zabbix_template" "demo_template" {
  host        = "template"
  name        = "template demo"
  description = "An exemple of template with item and trigger"
  groups      = [zabbix_host_group.demo_group.name]
  macro = {
    MACRO_TEMPLATE = "12"
  }
}

resource "zabbix_item" "demo_item" {
  name        = "demo item"
  key         = "demo.key"
  delay       = "34"
  description = "Item for the demo template"
  trends      = "300"
  history     = "25"
  host_id     = zabbix_template.demo_template.template_id
}

resource "zabbix_trigger" "demo_trigger" {
  description = "demo trigger"
  expression  = "{${zabbix_template.demo_template.host}:${zabbix_item.demo_item.key}.last()}={$MACRO_TEMPLATE}"
  priority    = 5
  status      = 0
}

# This virtual resource is responsible of ensuring no item and trigger is directly associated to the template
resource "zabbix_template_link" "demo_template_link" {
  template_id = zabbix_template.demo_template.id
  item {
    item_id = zabbix_item.demo_item.id
  }
  trigger {
    trigger_id = zabbix_trigger.demo_trigger.id
  }
}

Template dependencies

provider "zabbix" {
  user = "Admin"
  password = "zabbix"
  server_url = "http://localhost/api_jsonrpc.php"
}

resource "zabbix_host_group" "demo_group" {
  name = "Template demo group"
}

resource "zabbix_template" "template_1" {
  host        = "template_1"
  groups      = [zabbix_host_group.demo_group.name]
}

resource "zabbix_template_link" "demo_template_1_link" {
  template_id = zabbix_template.template_1.id
}

resource "zabbix_template" "template_2" {
  host = "template_2"
  groups = [zabbix_host_group.demo_group.name]
  linked_template = [ # use the template link template_id value to be sure that all template_1 dependencies has been updated
    zabbix_template.demo_template_1_link.template_id
  ]
}

resource "zabbix_template_link" "demo_template_2_link" {
  template_id = zabbix_template.template_2.id
}

terraform-provider-zabbix's People

Contributors

pdecat avatar xp-1000 avatar dainis avatar jboclara avatar azman0101 avatar gandous avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.