foltik / terraform-provider-vyos

VyOS Router Provider for Terraform (WIP)
MIT License
18 stars 7 forks source link

Best way to handle identical keys #20

Closed avanier closed 1 year ago

avanier commented 1 year ago

I'm trying to wrap my head around how to best handle identical keys, and none of the options seem particularly elegant. A good example is setting multiple ordered instances of the system name-server key.

If I mean to set nameservers in order of lookup for 8.8.8.8, 8.8.4.4, 1.1.1.1 I see that I can:

Option 1: Use sets

resource "vyos_config" "name-server" {
  for_each = toset([
    "8.8.8.8",
    "8.8.4.4",
    "1.1.1.1",
  ])
  key   = "system name-server"
  value = each.key
}

Using sets is great for state management, but it does not provide a guarantee of the order in which the elements will be set when making the API calls.

edit: just stubbed my toe into this not working. between the calls terraform realizes the key already exists.

Option 2: Use dependencies

resource "vyos_config" "name-server-1" {
  key   = "system name-server"
  value = "8.8.8.8"
}

resource "vyos_config" "name-server-2" {
  key   = "system name-server"
  value = "8.8.4.4"

  depends_on = vyos_config.name-server-1
}

I've also tried using vyos_config_block resources, but on the system object, it gets rightfully upset about there being other state it cannot control.

Ultimately, none of those options "feel right". I'm curious of how others have tackled this issue.

avanier commented 1 year ago

Nevermind, none of the options listed above work. Errr... still curious how to tackle this.

avanier commented 1 year ago

Nevermind some more. I just realized that both #15 and #19 aim to tackle this.