Did you know that you can navigate the posts by swiping left and right?

Setting up Zabbix on AWS with Terraform

20 Mar 2018 . category: tutorial . Comments
#terraform #docker #monitoring #aws

This blogpost contains the information necessary to setup Zabbix XXL on Amazon AWS using Docker and terraform.

The code for this blogpost can be found on github and the running cost of this setup will fall completely under the AWS Free Tier Usage. Outside the Free Tier Usage it will roughly be $38.30 per month, depending on your usage, for the non HA setup. It is safe to assume that the HA setup will cost twice as much.

During this tutorial, we will create the following AWS resources: IAM, EC2, ECS, RDS, Route53

Below is a visual representation about what will be created: AWS Stack



The AWS Command Line Interface (CLI) is a unified tool to manage your AWS services. With just one tool to download and configure, you can control multiple AWS services from the command line and automate them through scripts.

Please see the manual on Amazon AWS on how to install aws-cli.


Docker is the world’s leading software container platform. Developers use Docker to eliminate “works on my machine” problems when collaborating on code with co-workers. Operators use Docker to run and manage apps side-by-side in isolated containers to get better compute density. Enterprises use Docker to build agile software delivery pipelines to ship new features faster, more securely and with confidence for both Linux and Windows Server apps.

Please see the manual on Docker on how to install docker and on how to run an example hello-world application.


Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions.

Please see the manual on Terraform on how to install terraform.



A lot fo settings can be configured. The following configuration settings can be set in the file variables.tfvars. See variables.tfvars.example as example.

* [`aws_region`]: String(optional): [AWS Region](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#concepts-available-regions) you want to deploy this in. (default: `eu-west-1`)

* [`aws_profile`]: String(optional) [AWS Profile](http://docs.aws.amazon.com/cli/latest/userguide/cli-multiple-profiles.html). (default: `default`)

* [`aws_instance_type`]: String(optional) [AWS Instance type](https://aws.amazon.com/ec2/instance-types/) you want this application to run on. (default: `t2.nano`)

* [`aws_db_instance_type`]: String(optional) [AWS RDS Instance type](https://aws.amazon.com/rds/pricing/) you want this application to run on. (default: `db.t2.micro`)

* [`aws_db_backup_days`]: String(optional)Amount (days) how long database backups should be stored. 0 to disable (default: 7)

* [`aws_ami`]: String(optional) Amazon AMI to use (default: `ECS Optimized`)

* [`aws_certificate_arn`]: String(optional) Amazon Certificate Manager is not in terraform. Place the ARN here. If default, zabbix will run on HTTP instead of HTTPS. (default: `false`)

* [`aws_route53_hosted_zone_id`]: String(optional) The AWS Route53 hosted zone id you want the subdomain to be created on. If false, load balancer is your endpoint. (default: `false`, example: `ZE1U20IED0CW7`)

* [`aws_high_availability`]: String(optional) Wheter or not this cluster should be considered high available. Setting this to true means multiple AZ deployment (And an increase in costs!) (default: `false`)

* [`name`]: String(optional) Name for this application (default: `Zabbix`)

* [`db_password`]: String(required) Password for the RDS database. Choose something strong (default: `changeme`)

* [`ip_ssh_access`]: String(optional) Set to false to disable ssh access (recommended). CIDR block (add /32) that has SSH access into the instance. Can be your IP or a bastion host. (default: `false`, example ``)

* [`public_key`]: String(optional) The public key that has access to ssh into the zabbix instance. (default: `false`, example `ssh-rsa ....`)

* [`domain`]: String(optional) The domainname you want to run zabbix on. Only works if `aws_route53_hosted_zone_id` is also set! (default: `false`, example `zabbix.example.com`)

Starting Up

Once you got all the tools installed we can start launching our zabbix infrastructure.

  1. Go inside the terraform folder and run the command below to see an overview of all the resources that will be created.
    terraform plan -var-file=variables.tfvars

  2. While still being in the same folder, execute the command below to start creating the AWS resources.
    terraform apply -var-file=variables.tfvars

  3. When everything is successful, You'll see output that will look like this:
    Zabbix ECR Endpoint = 435551404480.dkr.ecr.eu-west-1.amazonaws.com/zabbix
    Zabbix Endpoint = https://zabbix-1844418752.eu-west-1.elb.amazonaws.com

  4. AWS Setup is running. Now we need to deploy the docker image. Go inside the docker folder and execute
    aws ecr get-login --no-include-email --region eu-west-1

  5. The previous command will return an output that starts with
    docker login -u AWS -p Xeg.....
    Copy that entire output and execute it.

  6. Execute
    docker build -t zabbix .
    to start building the docker image

  7. Execute
    docker tag test:latest [Zabbix ECR Endpoint]:latest
    Replace [Zabbix ECR Endpoint] with the Zabbix ECR Endpoint received in step 3

  8. As a last step we need to push the docker image to our newly created repository. Execute
    docker push [Zabbix ECR Endpoint]:latest
    Replace [Zabbix ECR Endpoint] with the Zabbix ECR Endpoint received in step 3

That’s it! in a moment your zabbix cluster will come online on [Zabbix Endpoint] (See step 3).

If there are any issues, please do let me know!


Thomas Van den Berge is a DevOps Cloud Engineer/Senior Backend Developer based in Belgium near the beautiful city of Ghent. In his spare time he likes to spend time with his daughter, work on his fishtanks and travel.