Random 我如何将一个随机八位元插值到地形中的CIDR块中?
我有以下random_test.tf Terraform文件,已成功初始化:Random 我如何将一个随机八位元插值到地形中的CIDR块中?,random,terraform,interpolation,ipv4,Random,Terraform,Interpolation,Ipv4,我有以下random_test.tf Terraform文件,已成功初始化: resource“random\u integer”“octet”{ 最小值=0 最大值=255 } 变量“基本cidr块”{ description=“RFC 1918范围内的A类CIDR块” default=“10.0.0.0/8” } 提供程序“空”{ base_cidr_block=“10.${random_integer.octet.result}.0.0/16” } 输出“ip_块”{ 值=var.base
resource“random\u integer”“octet”{
最小值=0
最大值=255
}
变量“基本cidr块”{
description=“RFC 1918范围内的A类CIDR块”
default=“10.0.0.0/8”
}
提供程序“空”{
base_cidr_block=“10.${random_integer.octet.result}.0.0/16”
}
输出“ip_块”{
值=var.base\U cidr\U块
}
我使用作为占位符来测试使用随机的第二个八位字节定义10.0.0.0/16 CIDR块。然而,基本cidr块始终是10.0.0/8
,尽管我希望它被分配类似10.100.0.0/16
,然后在标准输出上显示为ip块。相反,我总是得到默认值:
$ terraform plan
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# random_integer.octet will be created
+ resource "random_integer" "octet" {
+ id = (known after apply)
+ max = 255
+ min = 0
+ result = (known after apply)
}
Plan: 1 to add, 0 to change, 0 to destroy.
Changes to Outputs:
+ ip_block = "10.0.0.0/8"
运行
terraform apply
,然后始终将ip_block=“10.0.0.0/8”
发送到控制台。我做错了什么?以下是我的想法,尽管我可能不理解其意图
首先,我创建了一个模块。我正在使用随机整数,并设置一个守护者:
variable "netname" {
default = "default"
}
variable "subnet" {
default = "10.0.0.0/8"
}
resource "random_integer" "octet" {
min = 0
max = 255
keepers = {
netname = var.netname
}
}
output "rand" {
value = random_integer.octet.result
}
output "random-subnet" {
value = "${cidrsubnet("${var.subnet}", 8, random_integer.octet.result)}"
}
接下来,我调用模块,传入我的keeper和子网(可选):
module "get-subnet-1" {
source = "./module/"
netname = "subnet-1"
}
output "get-subnet-1" {
value = module.get-subnet-1.random-subnet
}
module "get-subnet-2" {
source = "./module/"
netname = "subnet-2"
}
output "get-subnet-2" {
value = module.get-subnet-2.random-subnet
}
最后,我的输出:
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Outputs:
get-subnet-1 = 10.2.0.0/16
get-subnet-2 = 10.6.0.0/16
申请完成!资源:添加1个,更改0个,销毁0个。
产出:
get-subnet-1=10.2.0.0/16
get-subnet-2=10.6.0.0/16