gmichels / terraform-provider-adguard

Terraform provider for AdGuard
https://registry.terraform.io/providers/gmichels/adguard/latest/docs
MIT License
10 stars 5 forks source link

Add a resource for static dhcp leases #70

Closed jogrie closed 1 year ago

jogrie commented 1 year ago

Hi Gustavo,

it would be very nice if you could add an resource for static dhcp leases.

My problem here ist that i want to provision a new machine all in one go (setting up the machine in proxmoxve, adding a dhcp lease, adding a reverse proxy configuration, propagating dhns names, etc). In addition i want to provision the dhcp leases independent from my home and my work pc.

Thats not possible at the momen, since i have to use the config resource.

For me it would be a quality of life improvement. What do you think about it?

Greetings

gmichels commented 1 year ago

Hey,

I don't think I fully understand your need, but as a guess, can't you get the output details of the created VMs into a locals variable and then use that to create a list of dicts for the dhcp leases? For the home/work question, I would need more context to understand if it makes sense.

If you could provide some examples of what you are trying to do, it would be great.

jogrie commented 1 year ago

Hi Gustavo,

using the VM variables is no problem to create resources, that works fine.

for the home / work question:

i have set up my adguard config via terraform on my home pc. now i create a new terraform project on my work pc to build a vm in my proxmox host, set a static dhcp lease in adguard and create a reverse proxy setting in nginx.

the probem here is that you can't create a static lease, without adding the dhcp config part

resource "adguard_config" "testlease" {
  dhcp = {

    static_leases = [{
      mac      = "aa:bb:cc:dd:ee:ff"
      ip       = "192.168.1.150"
      hostname = "testlease"
    }]
  }
}

throws the following error

╷
│ Error: Incorrect attribute value type
│
│   on graylog.tf line 40, in resource "adguard_config" "testlease":
│   40:   dhcp = {
│   41:     # interface = "eth0"
│   42:     # enabled   = true
│   43:     # ipv4_settings = {
│   44:     #   gateway_ip     = "192.168.1.1"
│   45:     #   subnet_mask    = "255.255.255.0"
│   46:     #   range_start    = "192.168.1.150"
│   47:     #   range_end      = "192.168.1.155"
│   48:     #   lease_duration = 7200
│   49:     # }
│   50:     static_leases = [{
│   51:       mac      = "aa:bb:cc:dd:ee:ff"
│   52:       ip       = "192.168.1.150"
│   53:       hostname = "testlease"
│   54:     }]
│   55:   }
│
│ Inappropriate value for attribute "dhcp": attribute "interface" is required

only adding the dhcp config fixes the problem, but leads to wiping the whole config set on the private pc losing all dns settings, all leases etc ..

resource "adguard_config" "testlease" {
  dhcp = {
    interface = "eth0"
    enabled   = true
    ipv4_settings = {
      gateway_ip     = "192.168.1.1"
      subnet_mask    = "255.255.255.0"
      range_start    = "192.168.1.150"
      range_end      = "192.168.1.155"
      lease_duration = 7200
    }

    static_leases = [{
      mac      = "aa:bb:cc:dd:ee:ff"
      ip       = "192.168.1.150"
      hostname = "testlease"
    }]
  }
}

so extracting the static lease into a own resource would fix this problem due not touching the other config parts. and as there are special api calls to create and remove static leases this should be no problem.

i hope you understand what i mean.

Greetings

gmichels commented 1 year ago

Hey,

I understand what you are trying to do with your home/work setup, but I don't feel like it is an appropriate use case. I'd expect the vast majority of people to have a single set of terraform configuration files for their ADG server, and in those cases, adding a DHCP lease when the DHCP server is not configured (missing interface and scope) will return a 400 from the ADG API (a very user-unfriendly message), so the provider has a validation in place to prevent this from happening.

I'd suggest you use a single set of configuration files for both your home and work use cases. Maybe something like a private git repository somewhere, and use remote state to keep everything in sync in all locations.

Thanks for the suggestion, but I feel it's an edge case, and I'd rather stick with how the majority will use the provider.

Thank you