Skip to content

Add support for dhcp server pools #218

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

Open
cipherbullet opened this issue Feb 28, 2025 · 4 comments
Open

Add support for dhcp server pools #218

cipherbullet opened this issue Feb 28, 2025 · 4 comments
Labels
enhancement New feature or request

Comments

@cipherbullet
Copy link

Hi,
I am trying to create dhcp server using restconf(as I don't see any resources for that)
when I do using curl, it works but when I do using restconf, it returns internal error!

this is my resource block:

resource "iosxe_restconf" "dhcp_pool_switch" {
    path = "Cisco-IOS-XE-native:native/ip/dhcp/pool"

    attributes = {
        "id" = "switch"
        "option.option-range.0.option-range" = 66
        "option.option-range.0.ascii-new" = "172.31.0.1"
        "option.option-range.0.ascii" = "172.31.0.1"

        "default-router.default-router-list.0" = "172.31.0.1"
        "dns-server.dns-server-list.0" = "172.31.0.1"
        
        "network.primary-network.number" = "172.31.0.0"
        "network.primary-network.mask" = "255.255.255.192"
    }
}

I even removed all options to test creation but there is no difference. I mean like this:

resource "iosxe_restconf" "dhcp_pool_switch" {
    path = "Cisco-IOS-XE-native:native/ip/dhcp/pool"

    attributes = {
        "id" = "switch"
    }
}
@danischm
Copy link
Member

This should be the correct syntax:

resource "iosxe_restconf" "dhcp_pool_switch" {
  path = "Cisco-IOS-XE-native:native/ip/dhcp/Cisco-IOS-XE-dhcp:pool=switch"

  attributes = {
    id                               = "switch"
    "network/primary-network/number" = "172.31.0.0"
    "network/primary-network/mask"   = "255.255.255.192"
  }

  lists = [
    {
      name = "option/option-range"
      key  = "option-range"
      items = [{
        option-range = "66"
        ascii        = "172.31.0.1"
      }]
    },
    {
      name   = "default-router/default-router-list"
      key = ""
      values = ["172.31.0.1"]
    },
    {
      name   = "dns-server/dns-server-list"
      key = ""
      values = ["172.31.0.1"]
    }
  ]
}

@danischm danischm added the enhancement New feature or request label Mar 23, 2025
@danischm danischm changed the title dhcp server creation doesn't work Add support for dhcp server pools Mar 23, 2025
@danischm
Copy link
Member

I will keep this issue open to track the addition of a native resource.

@cipherbullet
Copy link
Author

Honestly, I did it like this and it works:
but I also can try yours

resource "iosxe_restconf" "dhcp_pool_switch" {
  path = "Cisco-IOS-XE-native:native/ip/dhcp/Cisco-IOS-XE-dhcp:pool=switch"

  attributes = {
    "id"                                   = "switch"
    "network.primary-network.number"       = split("/", local.switch_cidr)[0]
    "network.primary-network.mask"         = local.switch_mask
    "default-router.default-router-list.0" = local.switch_ip
    "dns-server.dns-server-list.0"         = local.switch_ip

    "option.option-range.0.option-range" = 66
    "option.option-range.0.ascii-new"    = local.tftp_server_ip
    "option.option-range.0.ascii"        = local.tftp_server_ip

    "option.option-range.1.option-range" = 67
    "option.option-range.1.ascii-new"    = local.tftp_server_file
    "option.option-range.1.ascii"        = local.tftp_server_file
  }
}

@danischm
Copy link
Member

The .0. syntax works to push the config, but it fails to correctly read the config and you will have a constant drift when re-running Terraform.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants