disc / terraform-provider-pritunl

Pritunl Terraform provider

Home Page:https://pritunl.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

validation needed for fields requiring CIDR

dlethin opened this issue · comments

I created a server and accidentally forgot the number of bit at the end:

route {
     network =     "10.100.0.2"
     # should have been this
     #network =     "10.100.0.2/32"
     nat = false
   }

when applying the terraform plan, the server got created correctly, but then on a susequent plan, I got the following:

  # pritunl_server.test will be updated in-place
  ~ resource "pritunl_server" "test" {
        id                 = "[REDACTED]"
        name               = "test"
        # (30 unchanged attributes hidden)

      ~ route {
          + network = "10.100.0.2"
            # (1 unchanged attribute hidden)
        }
      - route {
          - nat     = false -> null
          - network = "10.100.0.2/32" -> null
        }
    }

Realizing my mistake, I then decided to update my plan correctly to this:

route {
     network =     "10.100.0.2/32"
     nat = false
   }

I thought running a plan then would show now changes, but instead I got this:

  # pritunl_server.test will be updated in-place
  ~ resource "pritunl_server" "test" {
        id                 = "REDACTED"
        name               = "test"
        # (30 unchanged attributes hidden)

      ~ route {
          + network = "10.20.0.2/32"
            # (1 unchanged attribute hidden)
        }
      - route {
          - nat     = false -> null
          - network = "10.20.0.2/32" -> null
        }
    }

And attempting to apply that change results in the following error:

pritunl_server.test: Modifying... [id=REDACTED]
╷
│ Error: Error on detaching route from the server: Non-200 response on deleting a route on the server
│ body=404 page not found
│
│   with pritunl_server.test,
│   on main.tf line 87, in resource "pritunl_server" "test":
│   87: resource "pritunl_server" "test" {
│

Can validation be added to require a route network to be valid CIDR?

After running into this problem, I tested this also with the network field for the pritunl_server resource and ran into issues as well:

resource "pritunl_server" "test" {
  name="test"

  network = "172.20.68.0/24"
  # should be valid CIDR like:
  network = "172.20.68.0"

When applying this plan to create the pritunl server, I get a 500 error:

pritunl_server.test: Creating...
╷
│ Error: Error on attaching server to the organization: Non-200 response on arrachhing an organization the server
│ body=500: Internal Server Error
│
│   with pritunl_server.test,
│   on main.tf line 87, in resource "pritunl_server" "test":
│   87: resource "pritunl_server" "test" {
│

I noticed in the pritunl admin UI a server with that name does get created, but there is no network value assigned to it.

Can validation be added for these fields to prevent this accidental state from occurring? Thanks.