Terraform Provider for Mikrotik RouterOS

Overview

Terraform Provider RouterOS

Purpose

This provider is intended to be used with Router OS 7 and above. It makes use of the REST API introduced with Router OS v7.

Currently Implemented

  • Interface
    • Bridge
      • Bridge VLAN
      • Bridge Port
    • VLAN
  • IP
    • DHCP Client
    • DHCP Server
    • Pool
    • Route

Usage

Please refer to the documentation

Changelog

See changelog.md

Comments
  • Problem getting it to work

    Problem getting it to work

    Describe the bug I want to play around with the provider and I am testing and can't get it to work. Get an Provider produced inconsistent result after apply error (see below). Testing on RouterOS 7.4. Is this a bug or do I do something wrong?

    To Reproduce I created a simple file: terraform { required_providers { routeros = { source = "GNewbury1/routeros" } } }

    provider "routeros" { hosturl = "https://10.252.10.1" username = "abc" password = "appeltaart" insecure = true }

    resource "routeros_ip_pool" "pool" { name = "my_ip_pool" ranges = "10.0.0.100-10.0.0.200" }

    Expected behavior It works..

    Stack Trace If applicable, add the stack trace the crash produced.

    Additional context Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:

    • create

    Terraform will perform the following actions:

    routeros_ip_pool.pool will be created

    • resource "routeros_ip_pool" "pool" {
      • id = (known after apply)
      • name = "my_ip_pool"
      • ranges = "10.0.0.100-10.0.0.200" }

    Plan: 1 to add, 0 to change, 0 to destroy.

    Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve.

    Enter a value: yes

    routeros_ip_pool.pool: Creating... ╷ │ Error: Provider produced inconsistent result after apply │ │ When applying changes to routeros_ip_pool.pool, provider "provider["registry.terraform.io/gnewbury1/routeros"]" │ produced an unexpected new value: Root resource was present, but now absent. │ │ This is a bug in the provider, which should be reported in the provider's own issue tracker.

    bug 
    opened by durandguru 4
  • Datasources that return array contain wrong values

    Datasources that return array contain wrong values

    Describe the bug I setup a RouterOS with two addresses (*1 and *2, using 10.0.9.1/24 and 192.168.88.1/24), the REST api also returns the correct values.

    Using the terraform provider, the list contains the same address twice and is missing the first one. When I create a third address, the array contains three times the last one.

    This is also reproducable for the interfaces and routes datasource.

    ip_addresses = {
      "addresses" = tolist([
        {
          "actual_interface" = "ether1"
          "address" = "192.168.88.1/24"
          "disabled" = true
          "dynamic" = false
          "id" = "*2"
          "interface" = "ether1"
          "invalid" = false
          "network" = "192.168.88.0"
        },
        {
          "actual_interface" = "ether1"
          "address" = "192.168.88.1/24"
          "disabled" = true
          "dynamic" = false
          "id" = "*2"
          "interface" = "ether1"
          "invalid" = false
          "network" = "192.168.88.0"
        },
      ])
      "id" = "terraform-20220120102446891700000001"
    }
    
    

    To Reproduce Setup multiple routes, addresses or interfaces and query those.

    Minimal terraform example:

    provider "routeros" {
      hosturl  = "https://10.0.9.150"
      username = "admin"
      password = ""
      insecure = true
    }
    
    data "routeros_interfaces" "interfaces" {}
    
    data "routeros_ip_routes" "routes" {}
    
    data "routeros_ip_addresses" "addresses" {}
    
    
    output "interfaces" {
      value = data.routeros_interfaces.interfaces
    }
    
    output "ip_addresses" {
      value = data.routeros_ip_addresses.addresses
    }
    
    output "routes" {
      value = data.routeros_ip_routes.routes
    }
    
    
    

    Expected behavior Array with the correct entries.

    bug 
    opened by deveth0 2
  • /system/identity set/get

    /system/identity set/get

    Because we cannot 'delete' a System Identity we just reset it back to the default MikroTik. If that's not the best idea, we can instead just make the delete a 'no op' and skip it.

    Closes #55

    opened by michael-robbins 1
  • Add ipv6_neighbor_discovery

    Add ipv6_neighbor_discovery

    This seemed to work well during minimal testing, it could use a thorough review though.

    I also couldn't get the doc generation to work, so you may need to add those.

    opened by rifelpet 1
  • Bridge interface: pvid out of range

    Bridge interface: pvid out of range

    Describe the bug Not an expert for RouterOS but when I want to create a bridge interface without setting the pvid parameter, I'm getting following error:

    When applying changes to routeros_interface_bridge.bridge, provider "provider[\"registry.terraform.io/gnewbury1/routeros\"]" produced an unexpected new value: Root resource was present, but now absent.
    

    After looking into Terraform debug logs I noticed following line:

    {"@level":"warn","@message":"unexpected data","@timestamp":"2022-10-23T14:04:28.141949+02:00","registry.terraform.io/gnewbury1/routeros:stdout":"value of pvid out of range (1..4094)"}
    

    Based on the error and according to the [docs[(https://help.mikrotik.com/docs/display/ROS/Bridging+and+Switching) I'm assuming that default value should be 1 and not 0 as in the current state:

    "pvid": {
        Type:     schema.TypeInt,
        Optional: true,
        Default:  0,
    },
    

    To Reproduce Try to apply example configuration of routeros_interface_bridge

    Expected behavior Successful creation of bridge interface

    Stack Trace

    routeros_interface_bridge.bridge: Modifying... [id=*<id>]
    ....
    {"@level":"trace","@message":"received data","@module":"provider.stdio","@timestamp":"2022-10-23T14:04:28.141913+02:00","channel":"STDOUT","len":36}
    {"@level":"warn","@message":"unexpected data","@timestamp":"2022-10-23T14:04:28.141949+02:00","registry.terraform.io/gnewbury1/routeros:stdout":"value of pvid out of range (1..4094)"}
    ....
    │ Error: Provider produced inconsistent result after apply
    │
    │ When applying changes to routeros_interface_bridge.bridge, provider "provider[\"registry.terraform.io/gnewbury1/routeros\"]" produced an unexpected new value: Root resource was present, but now absent.
    │
    │ This is a bug in the provider, which should be reported in the provider's own issue tracker.
    

    Additional context Versions: Terraform: 1.3.3 Provider: 0.3.4 RouterOS: 7.5

    bug 
    opened by JanNemcik 0
  • Changing the identity does not work on a CRS112

    Changing the identity does not work on a CRS112

    My code:

    #tfvars file content: identity = "mt-crs112"
    
    variable "identity" {
      type = string
    }
    
    resource "routeros_system_identity" "ros_identity" {
        name = var.identity
    }
    

    Output of terraform apply:

    routeros_system_identity.ros_identity: Refreshing state... [id=mt-oldname]
    
    Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the
    following symbols:
      ~ update in-place
    
    Terraform will perform the following actions:
    
      # routeros_system_identity.ros_identity will be updated in-place
      ~ resource "routeros_system_identity" "ros_identity" {
            id   = "mt-oldname"
          ~ name = "mt-oldname" -> "mt-crs112"
        }
    
    Plan: 0 to add, 1 to change, 0 to destroy.
    routeros_system_identity.ros_identity: Modifying... [id=mt-oldname]
    routeros_system_identity.ros_identity: Modifications complete after 1s [id=mt-oldname]
    

    After apply the name is still "mt-oldname".

    Mikrotik model: CRS112 RouterOS: 7.6 (same result with 7.4) Terraform: v1.3.7 Provider: v0.4.0 Go: go1.19.4

    bug 
    opened by MischaBoender 0
  • Ability to manage SSL Certificates

    Ability to manage SSL Certificates

    It would be very cool to help add support for let's encrypt by combining with the acme provider, things needed for this:

    Lifecycle of certificate Assign to services, api, www, ikev2

    enhancement 
    opened by Russell-IO 0
  • routeros_ip_dhcp_server - Provider produced inconsistent result after apply

    routeros_ip_dhcp_server - Provider produced inconsistent result after apply

    Describe the bug This happens when running terraform apply. I am also unable to make an ip address resource. It throws error no matter what I try. My below code was working for a bit then started giving this error after I kept trying to get the IP address resource to work.

    To Reproduce

    terraform {
      required_providers {
        routeros = {
          source = "GNewbury1/routeros"
        }
      }
    }
    
    provider "routeros" {
      hosturl  = "https://172.21.0.1"
      username = "username"
      password = "password"
      insecure = true
    }
    
    
    locals {
      network71 = {
        name = "vlan71-smartDevices"
        address = "10.71.0.0"
        gateway = "10.71.0.1"
        cidr = "/24"
        vlan = 71
      }
      domain   = "yoshi.lan"
    }
    
    resource "routeros_interface_vlan" "vlan-vlan71-smartDevices" {
      interface = "bridge-lan"
      name      = local.network71.name
      vlan_id   = local.network71.vlan
    }
    resource "routeros_ip_pool" "pool-vlan71-smartDevices" {
      name   = local.network71.name
      ranges = "10.0.71.100-10.0.71.200"
    }
    resource "routeros_ip_dhcp_server_network" "dhcpNetwork-vlan71-smartDevices" {
      address    = format("%s%s",local.network71.address,local.network71.cidr)
      gateway    = local.network71.gateway
      dns_server = local.network71.gateway
      domain     = local.domain
    }
    resource "routeros_ip_dhcp_server" "dhcpServer-vlan71-smartDevices" {
      address_pool = local.network71.name
      interface    = local.network71.name
      name         = local.network71.name
    }
    

    Output:

    routeros_ip_dhcp_server.dhcpServer-vlan71-smartDevices: Creating...
    routeros_interface_vlan.vlan-vlan71-smartDevices: Creating...
    routeros_ip_pool.pool-vlan71-smartDevices: Creating...
    routeros_ip_dhcp_server_network.dhcpNetwork-vlan71-smartDevices: Creating...
    routeros_ip_dhcp_server_network.dhcpNetwork-vlan71-smartDevices: Creation complete after 0s [id=*18]
    routeros_ip_pool.pool-vlan71-smartDevices: Creation complete after 0s [id=*1C]
    routeros_interface_vlan.vlan-vlan71-smartDevices: Creation complete after 0s [id=*24]
    ╷
    │ Error: Provider produced inconsistent result after apply
    │ 
    │ When applying changes to routeros_ip_dhcp_server.dhcpServer-vlan71-smartDevices, provider
    │ "provider[\"registry.terraform.io/gnewbury1/routeros\"]" produced an unexpected new value: Root resource was
    │ present, but now absent.
    │ 
    │ This is a bug in the provider, which should be reported in the provider's own issue tracker.
    

    Expected behavior Expected to run without error and create the dhcp server resource

    Stack Trace If applicable, add the stack trace the crash produced.

    Additional context Add any other context about the problem here.

    bug 
    opened by emerconghaile 0
  • Ability for create containers

    Ability for create containers

    Is your feature request related to a problem? Please describe. A container is MikroTik's implementation of Linux containers, allowing users to run containerized environments within RouterOS. For example run traefik would be very useful!

    Describe the solution you'd like Manage lifecycle for containers, env variables, versions, etc.

    Additional context Here oficial guide for create container https://help.mikrotik.com/docs/display/ROS/Container

    enhancement 
    opened by metajiji 0
  • Firewall Filter Rule Create - src_port is pulling

    Firewall Filter Rule Create - src_port is pulling "Port" not "src_port" in the return

    Describe the bug In the code, the returned object (d.set) has a property (src_port) that is being filled by the returned object's "Port" attribute. This should be filled by the returned object's "SrcPort" attribute.

    To Reproduce In the routeros/resource_ip_firewall_filter.go file, on line 475, the line reads: d.Set("src_port", res.Port).

    Expected behavior In the routeros/resource_ip_firewall_filter.go file, on line 475, the line should read: d.Set("src_port", res.SrcPort).

    Stack Trace No Stack Trace, does not crash, just returns incorrect data.

    Additional context No additional context here.

    bug 
    opened by scotch16 1
Releases(v0.4.0)
Owner
Guy Newbury
Guy Newbury
Terraform provider to help with various AWS automation tasks (mostly all that stuff we cannot accomplish with the official AWS terraform provider)

terraform-provider-awsutils Terraform provider for performing various tasks that cannot be performed with the official AWS Terraform Provider from Has

Cloud Posse 25 Dec 8, 2022
Terraform Provider for Azure (Resource Manager)Terraform Provider for Azure (Resource Manager)

Terraform Provider for Azure (Resource Manager) Version 2.x of the AzureRM Provider requires Terraform 0.12.x and later, but 1.0 is recommended. Terra

null 0 Oct 16, 2021
Terraform-provider-mailcow - Terraform provider for Mailcow

Terraform Provider Scaffolding (Terraform Plugin SDK) This template repository i

Owen Valentine 0 Dec 31, 2021
Terraform-provider-buddy - Terraform Buddy provider For golang

Terraform Provider for Buddy Documentation Requirements Terraform >= 1.0.11 Go >

Buddy 1 Jan 5, 2022
Terraform-provider-vercel - Terraform Vercel Provider With Golang

Vercel Terraform Provider Website: https://www.terraform.io Documentation: https

Vercel 80 Dec 14, 2022
Terraform-provider-age - Age Terraform Provider with golang

Age Terraform Provider This provider lets you generate an Age key pair. Using th

ConsenSys Software 0 Feb 15, 2022
kube-champ 43 Oct 19, 2022
Terraform-in-Terraform: Execute Modules directly from the Terraform Registry

Terraform-In-Terraform Provider This provider allows running Terraform in Terraform. This might seem insane but there are some edge cases where it com

WeakPixel 39 Dec 25, 2022
Terraform utility provider for constructing bash scripts that use data from a Terraform module

Terraform Bash Provider This is a Terraform utility provider which aims to robustly generate Bash scripts which refer to data that originated in Terra

Martin Atkins 33 Sep 6, 2022
Quick start repository for creating a Terraform provider using terraform-plugin-framework

Terraform Provider Scaffolding (Terraform Plugin Framework) This template repository is built on the Terraform Plugin Framework. The template reposito

HashiCorp 70 Dec 15, 2022
Terraform Provider Scaffolding (Terraform Plugin SDK)

Terraform Provider Scaffolding (Terraform Plugin SDK) This template repository is built on the Terraform Plugin SDK. The template repository built on

Brian Flad 0 Feb 8, 2022
OpenAPI Terraform Provider that configures itself at runtime with the resources exposed by the service provider (defined in a swagger file)

Terraform Provider OpenAPI This terraform provider aims to minimise as much as possible the efforts needed from service providers to create and mainta

Daniel I. Khan Ramiro 228 Dec 26, 2022
Hashicups-tf-provider - HashiCups Terraform Provider Tutorial

Terraform Provider HashiCups Run the following command to build the provider go

Andrew Xie 1 Jan 10, 2022
Terraform-grafana-dashboard - Grafana dashboard Terraform module

terraform-grafana-dashboard terraform-grafana-dashboard for project Requirements

hadenlabs 1 May 2, 2022
Puccini-terraform - Enable TOSCA for Terraform using Puccini

(work in progress) TOSCA for Terraform Enable TOSCA for Terraform using Puccini.

Tal Liron 3 Jun 27, 2022
Terraform-ncloud-docs - Terraform-ncloud-docs

terraform-ncloud-docs Overview This docs help to use terraform creation server C

Naver Cloud Platform 2 Oct 2, 2022
Terraform-house - Golang Based terraform automation example using tf.json

Terraform House Manage your own terraform workflow using go language, with the b

Bayu Rizky Ramadhan 0 Feb 17, 2022
LTF is a minimal, transparent Terraform wrapper. It makes Terraform projects easier to work with.

LTF Status: alpha LTF is a minimal, transparent Terraform wrapper. It makes Terraform projects easier to work with. In standard Terraform projects, th

Raymond Butcher 23 Nov 19, 2022
Terraform Controller manages the life cycles of a terraform resource, allowing developers to self-serve dependencies in a controlled manner.

TERRAFORM CONTROLLER Terraform Controller manages the life cycles of a terraform resource, allowing developers to self-serve dependencies in a control

appvia 53 Dec 15, 2022