有没有一种程序性的方法来在Terraform中进行半CIDR块?
我有一个CIDR块,我想将其完全放一半,以便我可以在Terraform项目中使用两个范围。
例如 10.10.10.0/24
,其中包括范围内的IPS 10.10.10.0-10.10.10.255
可以拆分为 10.10.10.0/25
& 10.10.10.10.128/25
我已经尝试使用 cidrsubnet函数,但我真的不明白如何使用它从第一范围到第二范围。
对此的任何帮助将不胜感激!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以用
cidrsubnet
如您所指出的那样。
说明:
cidrsubnet
获取3个参数:cidrsubnet(前缀,newbits,netnum)
。前缀
是您要切成两半的实际CIDR范围。newbits
是您要扩展前缀的附加位数。例如,如果您具有/24
前缀,并且想要具有/25
前缀,则newbits
是25和24之间的差异:25-24 = 1
netnum
是一个整数,不超过newbits
二进制数字。在我们的情况下,可以是0
或1
。0
将是10.10.10.0/25
的范围,而1
将代表下半年,为10.10.10.10.10.128/25
。为了给您另一个示例,这使得它更容易理解,让我们剪切
10.10.10.0/24
如果4个范围:我们知道,我们需要
/26
范围,所以26-24 = 2
newbits
。对于netnum
,我们可以有0、1、2、3,其中二进制数字为00
,01
,10
,<代码> 11 。This can be done with
cidrsubnet
as you pointed out.Explenation:
cidrsubnet
takes 3 arguments:cidrsubnet(prefix, newbits, netnum)
.prefix
is the actual CIDR range you want to cut in half.newbits
is the number of additional bits which you want to extend the prefix. For example, if you have/24
prefix and you want to have/25
prefixes,newbits
is the difference between 25 and 24:25 - 24 = 1
netnum
is a whole number which is no more thannewbits
binary digits. In our case it can be either0
or1
.0
will be the range of10.10.10.0/25
, while1
will represent the second half, being10.10.10.128/25
.To give you another example, which makes it more understandable, lets cut
10.10.10.0/24
if 4 ranges:We know, that we need
/26
ranges, so26 - 24 = 2
for thenewbits
. Fornetnum
, we can have 0, 1, 2, 3, for which in the binary digits are00
,01
,10
,11
.