Open peteleblond opened 3 years ago
Hey @peteleblond, thanks for the report.
I upgraded my terraform version to v1.0.1, but I haven't been able to reproduce it. It appears that this script code is not handling errors before running a command (here and here) :(
Are you able to compile the provider yourself? If so, please apply this diff with git apply
and then reproduce the issue so we can get a better idea of what the error is
diff --git a/client/scheduler.go b/client/scheduler.go
index bafc686..11896e2 100644
--- a/client/scheduler.go
+++ b/client/scheduler.go
@@ -16,6 +16,11 @@ type Scheduler struct {
func (client Mikrotik) FindScheduler(name string) (*Scheduler, error) {
c, err := client.getMikrotikClient()
+
+ if err != nil {
+ return nil, err
+ }
+
cmd := []string{"/system/scheduler/print", "?name=" + name}
log.Printf("[INFO] Running the mikrotik command: `%s`", cmd)
r, err := c.RunArgs(cmd)
@@ -37,6 +42,10 @@ func (client Mikrotik) FindScheduler(name string) (*Scheduler, error) {
func (client Mikrotik) DeleteScheduler(name string) error {
c, err := client.getMikrotikClient()
+ if err != nil {
+ return err
+ }
+
scheduler, err := client.FindScheduler(name)
if err != nil {
@@ -53,6 +62,10 @@ func (client Mikrotik) DeleteScheduler(name string) error {
func (client Mikrotik) CreateScheduler(s *Scheduler) (*Scheduler, error) {
c, err := client.getMikrotikClient()
+ if err != nil {
+ return nil, err
+ }
+
cmd := Marshal("/system/scheduler/add", s)
log.Printf("[INFO] Running the mikrotik command: `%s`", cmd)
diff --git a/client/script.go b/client/script.go
index 9885128..2e8fd59 100644
--- a/client/script.go
+++ b/client/script.go
@@ -21,6 +21,9 @@ func (s *Script) Policy() []string {
func (client Mikrotik) CreateScript(name, owner, source string, policies []string, dontReqPerms bool) (*Script, error) {
c, err := client.getMikrotikClient()
+ if err != nil {
+ return nil, err
+ }
policiesString := strings.Join(policies, ",")
nameArg := fmt.Sprintf("=name=%s", name)
@@ -85,6 +88,9 @@ func (client Mikrotik) UpdateScript(name, owner, source string, policy []string,
func (client Mikrotik) DeleteScript(name string) error {
c, err := client.getMikrotikClient()
+ if err != nil {
+ return err
+ }
script, err := client.FindScript(name)
@@ -101,6 +107,10 @@ func (client Mikrotik) DeleteScript(name string) error {
func (client Mikrotik) FindScript(name string) (*Script, error) {
c, err := client.getMikrotikClient()
+
+ if err != nil {
+ return nil, err
+ }
cmd := []string{"/system/script/print", "?name=" + name}
log.Printf("[INFO] Running the mikrotik command: `%s`", cmd)
r, err := c.RunArgs(cmd)
If that will be difficult then we can get that change merged into master, create a new release and have you try it again.
This code also creates a new connection for each function called, which is inefficient and I believe is leaking sockets. How many resources are in this terraform configuration?
Hi @ddelnano
Thanks for checking this out. Great work with this Provider, it's going to be immensely useful!
Currently, there are only 2 resources in my TF config, one of each type mikrotik_script
and mikrotik_scheduler
.
I'm afraid I'm not sure how to compile this myself, though I'll try and look it up when I get a chance. If you could get the change merged into master I'll test again as soon as I can.
I have that change included in v0.6.2. Please install v0.6.2 (it should be pushed to the terraform registry in the next hour or so), reproduce the problem and attach your logs again and hopefully we will have a better clue 🤞
Sorry, I might have the wrong end of the stick here, but v0.6.2 doesn't seem to be in the TF registry yet, is that expected? I was having a play with filesystem_mirror
by cloning the code tagged v0.6.2, but I'm back to compiling it again, which I haven't yet figured out!
Am I missing something?
Sorry, it is now. I forgot to publish the release on github, which is why it was hidden.
@peteleblond would appreciate if you get a chance to try out the latest release.
Using provider version 0.6.0 and Terraform 1.0.0 & 1.0.1 it appears that the provider intermittently fails to initiate MikroTik API when running (and re-running) a
terraform plan
orterraform apply
. This appears to happen intermittently even if the code remains totally unchanged. Usingtcpdump
, I've confirmed that API traffic can be seen when the terraform operation suceeds, but there is no API connection attempt when the this problem is encountered.Example error message (for
terraform plan
):Other relevant info:
In my configuration, Terraform is only configured to manage MirktoTik resources
mikrotik_script
andmikrotik_scheduler
.Provider config: