thousandeyes / terraform-provider-thousandeyes

ThousandEyes Terraform Provider
Apache License 2.0
21 stars 26 forks source link

fix: fixes group ordering, no longer required #107

Closed pedro-te closed 2 years ago

pedro-te commented 2 years ago

Additionally fixes type of builtin field in the agent groups (it was causing the provider to crash panic: reflect.Set: value of type int is not assignable to type bool).

This fixes https://github.com/thousandeyes/terraform-provider-thousandeyes/issues/105

TypeList is an ordered list, but users shouldn't have to worry about the order in which group blocks are placed in the resource:

resource "thousandeyes_agent_to_server" "example" {
  test_name      = "example"
  interval       = 120
  alerts_enabled = false
  use_public_bgp = false
  enabled = false

  server = "www.thousandeyes.com"

  agents {
    agent_id = 1234
  }

  groups {
    group_id = 1234
  }

  groups {
    group_id = 5678
  }
}

With typeList, terraform will care about the order of the groups, but with typeSet, order is not important (it's also a set meaning items can't be repeated, which applies here).

Additionally, the default value for type and name should be an empty string. We're sending null and storing that in the state, but then on the next terraform plan, the API will send empty strings in type and name. Terraform will compare that to the nulls in the state and think that there were outside changes made to the resource. If we send empty strings as default, this no longer happens.

My local tests show that this works as expected and terraform won't try to change the order on every run.

Unit tests pass:

?       github.com/thousandeyes/terraform-provider-thousandeyes [no test files]
ok      github.com/thousandeyes/terraform-provider-thousandeyes/thousandeyes    0.480s