siderolabs / terraform-provider-talos

Mozilla Public License 2.0
125 stars 17 forks source link

Problem patching data source `talos_machine_configuration` with `config_patches` #89

Closed flpajany closed 1 year ago

flpajany commented 1 year ago

Hello,

I am trying to set some config_patches operations in data source talos_machine_configuration but I have some errors.

In particular, I want to change the controlplane configuration with static IP allocated by infoblox and I put the code below for config_patches :

data "talos_machine_configuration" "controlplane" {
  for_each                    = toset(var.cluster_controlplanes)
  cluster_name     = var.cluster_name
  cluster_endpoint = var.cluster_endpoint
  machine_type     = "controlplane"
  machine_secrets  = talos_machine_secrets.this.machine_secrets
  docs = false
  examples = false
  config_patches = [
    templatefile("${path.module}/templates/cp.patch.test.yaml.tmpl", {
      hostname     = each.value
      ip = infoblox_ip_allocation.vm.allocated_ipv4_addr
    })
  ]
}

The patch file cp.patch.test.yaml.tmpl looks like this :

- op: replace
  path: /machine/network
  value:
    interfaces:
      - interface: eth0
        addresses:
          - ${ip}/24
        routes:
          - network: 0.0.0.0/0
            gateway: <some gateway>
            metric: 1024
        vip:
          ip: <some vip>
    nameservers:
      - <ns server1 ip>
      - <ns server2 ip>
    hostname: ${hostname}

When I apply the plan, I have theses errors :

╷ │ Error: failed to generate machine configuration │ │ with module.cluster.data.talos_machine_configuration.controlplane, │ on modules/cluster_talos/main.tf line 43, in data "talos_machine_configuration" "controlplane": │ 43: data "talos_machine_configuration" "controlplane" { │ │ failure applying rfc6902 patches to talos machine config: replace operation does not apply: doc is missing path: /machine/network: missing value

Could you help ?

Regards,

frezbo commented 1 year ago

you'd have to use:

- op: add
  path: /machine/network

Also it's now recommended to strategic merge patching:

machine:
  network:
    interfaces: ..............
    hostname: <>
flpajany commented 1 year ago

Hello @frezbo,

I already tried "- op: add" and it is the same :

│ Error: failed to generate machine configuration │ │ with module.cluster.data.talos_machine_configuration.controlplane, │ on modules/cluster_talos/main.tf line 43, in data "talos_machine_configuration" "controlplane": │ 43: data "talos_machine_configuration" "controlplane" { │ │ failure applying rfc6902 patches to talos machine config: add operation does not apply: doc is missing path: "/machine/network": missing value

But... the strategic merge patching is working !

Thx a lot for your answer. 👍