Skip to content
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

cidrsubnets fails on all-zero subnet #35486

Open
mxk opened this issue Jul 22, 2024 · 1 comment
Open

cidrsubnets fails on all-zero subnet #35486

mxk opened this issue Jul 22, 2024 · 1 comment
Labels
bug new new issue not yet triaged upstream

Comments

@mxk
Copy link

mxk commented Jul 22, 2024

Terraform Version

Terraform v1.9.1
on windows_amd64

Terraform Configuration Files

locals {
  cidr = ["0.0.0.0/1", "128.0.0.0/1"]
}

output "cidrsubnet" {
  value = [for v in local.cidr : [cidrsubnet(v, 1, 0), cidrsubnet(v, 1, 1)]]
}

output "cidrsubnets" {
  value = [for v in local.cidr : try(cidrsubnets(v, 1, 1), "error")]
}

Debug Output

https://gist.github.com/mxk/c1b54ada0c08ecaae0296420904668f5

Expected Behavior

Both outputs should be identical.

Actual Behavior

cidrsubnets("0.0.0.0/1", 1, 1) fails with Invalid value for "newbits" parameter: not enough remaining address space for a subnet with a prefix of 2 bits after 192.0.0.0/2. (if the try call is removed).

Steps to Reproduce

  1. terraform plan

Additional Context

No response

References

No response

@mxk mxk added bug new new issue not yet triaged labels Jul 22, 2024
@apparentlymart
Copy link
Contributor

Thanks for reporting this, @mxk.

I think the cause of this behavior is upstream in github.com/apparentlymart/go-cidr, in the NextSubnet function which seems to have a special case for all-zero addresses: https://github.com/apparentlymart/go-cidr/blob/d07067359aee8ee9101c1a79a4f286cf0cea059f/cidr/cidr.go#L195-L197

I don't recall what that special case was intending to achieve -- it's been a long time since that code was merged -- so I think it'll take some further poking to understand why that was there and whether it's load-bearing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug new new issue not yet triaged upstream
Projects
None yet
Development

No branches or pull requests

2 participants