Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: default alert is set to null with each apply even after applying change #165

Closed
Sraza11 opened this issue Jan 15, 2024 · 6 comments
Closed
Labels
bug Something isn't working

Comments

@Sraza11
Copy link

Sraza11 commented Jan 15, 2024

What versions are you using?

2.0.8

What did you expect to happen?

once I apply a resource it should NOT show that an alert is getting set from a value to null

What actually happened?

once you apply the following code and your run terraform apply or plan you will see that alert is getting set from default to null.

terraform plan

thousandeyes_agent_to_server.TE_TEST will be updated in-place
  ~ resource "thousandeyes_agent_to_server" "TE_TEST" {
      ~ alerts_enabled         = false -> true
        id                     = "4634087"
        # (24 unchanged attributes hidden)

      - alert_rules {
          - rule_id = 448256 -> null
        }

        # (1 unchanged block hidden)
    }

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

--- Actual resource

resource "thousandeyes_agent_to_server" "TE_TEST" {
  test_name              = "NO ACTION NEEDD TEST ONLY"
  interval               = 120
  alerts_enabled         = true
  description            = "test"
  server                 = "1.1.1.1"
  protocol               = "ICMP"
  enabled                = false
#  mtu_measurements       = false
 # bandwidth_measurements = false
  agents {
    agent_id = 3
  }
}

Terraform code to reproduce the bug

resource "thousandeyes_agent_to_server" "TE_TEST" {
  test_name              = "NO ACTION NEEDD TEST ONLY"
  interval               = 120
  alerts_enabled         = true
  description            = "test"
  server                 = "1.1.1.1"
  protocol               = "ICMP"
  enabled                = false
#  mtu_measurements       = false
 # bandwidth_measurements = false
  agents {
    agent_id = 3
  }
}

Any additional comments or code?

without fixing this issue I can not move from 2.0.5 to 2.0.8 version. and I need the functionality of 2.0.8 version

Steps to reproduce the bug

apply the resource and re run the plan you will see the bug

resource "thousandeyes_agent_to_server" "TE_TEST" {
  test_name              = "NO ACTION NEEDD TEST ONLY"
  interval               = 120
  alerts_enabled         = true
  description            = "test"
  server                 = "1.1.1.1"
  protocol               = "ICMP"
  enabled                = false
 mtu_measurements       = false
 bandwidth_measurements = false
  agents {
    agent_id = 3
  }
}
@Sraza11 Sraza11 added the bug Something isn't working label Jan 15, 2024
@Sraza11 Sraza11 changed the title [Bug]: default alert is sent to null with each apply even after applying change [Bug]: default alert is set to null with each apply even after applying change Jan 15, 2024
@joaomper-TE
Copy link
Contributor

Hey @Sraza11, thanks for reporting. Can you confirm that this happens in 2.0.8 only but not in 2.0.5?

@joaomper-TE
Copy link
Contributor

joaomper-TE commented Jan 16, 2024

@Sraza11 after looking a bit more into this, it looks like this was introduced by the fix in #151.

However, we can't do much about it at this point, since it's the way Terraform works as this is a resource created outside of Terraform - and in this case, since these are default Alert Rules we don't want to have them managed from Terraform.

Also, there's a super easy workaround for this, which is to simply add the default alert_rule id to the test:

 resource "thousandeyes_agent_to_server" "TE_TEST" {
  test_name              = "NO ACTION NEEDD TEST ONLY"
  interval               = 120
  alerts_enabled         = true
  description            = "test"
  server                 = "1.1.1.1"
  protocol               = "ICMP"
  enabled                = true

  alert_rules {
          rule_id = 921610 
        }
        
  agents {
    agent_id = 3
   }
 }

Is this an acceptable solution for you?

@Sraza11
Copy link
Author

Sraza11 commented Jan 16, 2024

Hey @Sraza11, thanks for reporting. Can you confirm that this happens in 2.0.8 only but not in 2.0.5?

yes, this only happens with version > 2.0.5

@Sraza11
Copy link
Author

Sraza11 commented Jan 16, 2024

@Sraza11 after looking a bit more into this, it looks like this was introduced by the fix in #151.

However, we can't do much about it at this point, since it's the way Terraform works as this is a resource created outside of Terraform - and in this case, since these are default Alert Rules which we don't want to have managed from Terraform.

Also, there's a super easy workaround for this, which is to simply add the default alert_rule id to the test:

 resource "thousandeyes_agent_to_server" "TE_TEST" {
  test_name              = "NO ACTION NEEDD TEST ONLY"
  interval               = 120
  alerts_enabled         = true
  description            = "test"
  server                 = "1.1.1.1"
  protocol               = "ICMP"
  enabled                = true

  alert_rules {
          rule_id = 921610 
        }
        
  agents {
    agent_id = 3
   }
 }

Is this an acceptable solution for you?

that is not going to work for me since I have many hundreds of tests that are defined without alert rule and default alert takes over. if there is no way around I suppose adding an alert rule to each test will be one way to fix this issue.

this was not happening until version 2.0.5

@joaomper-TE
Copy link
Contributor

Yeah, like I said this happens because of #151 which fixes the fact that default alert rules were not showing up on the ids. And after 2.0.5 the behavior was corrected.

Now, the fact that a default alert rule is assigned to a test that has none when defined, I guess it should be dealt in one of 3 ways:

  1. Assign the default alert rule to the tests when defining them (you have the id, so should be straightforward)
  2. Try to somehow import the state with the default alert rules (haven't tested this one myself) - see Import State section this link
  3. Create a new alert rule as you mentioned

Sorry if the response is not what you wanted, but in this case it does seem that we are battling a bit with the way Terraform works.

@Sraza11
Copy link
Author

Sraza11 commented Jan 16, 2024

Yeah, like I said this happens because of #151 which fixes the fact that default alert rules were not showing up on the ids. And after 2.0.5 the behavior was corrected.

Now, the fact that a default alert rule is assigned to a test that has none when defined, I guess it should be dealt in one of 3 ways:

1. Assign the default alert rule to the tests when defining them (you have the id, so should be straightforward)

2. Try to somehow import the state with the default alert rules (haven't tested this one myself) - see `Import State` section this [link](https://leonardo-loch.medium.com/using-resources-created-outside-of-the-current-terraform-state-a0cc68cd606b)

3. Create a new alert rule as you mentioned

Sorry if the response is not what you wanted, but in this case it does seem that we are battling a bit with the way Terraform works.

no worries, I can work on this as long as it is a feature and not a bug.

@Sraza11 Sraza11 closed this as completed Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants