Terraform中交互变量的加载顺序
这是我的variables.tf文件Terraform中交互变量的加载顺序,terraform,Terraform,这是我的variables.tf文件 variable vpc-count { description = "Number of VPC to create" } variable "vpc1" { description = "Enter the CIDR for vpc1" } variable "vpc2" { description = "Enter the CIDR for vpc2" } variable subnet-count { description ="Ent
variable vpc-count { description = "Number of VPC to create" }
variable "vpc1" { description = "Enter the CIDR for vpc1" }
variable "vpc2" { description = "Enter the CIDR for vpc2" }
variable subnet-count { description ="Enter the number of subnets for vpc" }
variable "sub1vpc1" { description = "Enter the CIDR for subnet1 of vpc1" }
variable "sub2vpc1" { description = "Enter the CIDR for subnet2 of vpc1" }
variable "sub1vpc2" { description = "Enter the CIDR for subnet2 of vpc1" }
variable "sub2vpc2" { description = "Enter the CIDR for subnet2 of vpc2" }
不指定这些值的原因是,需要进行交互,并允许用户输入vpc cidr、子网cidr等的相关值
但在进入“地形计划”时。它会提示输入值:问题,但不是按照variables.tf文件中提到的顺序
variable vpc-count { description = "Number of VPC to create" }
variable "vpc1" { description = "Enter the CIDR for vpc1" }
variable "vpc2" { description = "Enter the CIDR for vpc2" }
variable subnet-count { description ="Enter the number of subnets for vpc" }
variable "sub1vpc1" { description = "Enter the CIDR for subnet1 of vpc1" }
variable "sub2vpc1" { description = "Enter the CIDR for subnet2 of vpc1" }
variable "sub1vpc2" { description = "Enter the CIDR for subnet2 of vpc1" }
variable "sub2vpc2" { description = "Enter the CIDR for subnet2 of vpc2" }
例如:第一个问题来自
variable "sub1vpc1" { description = "Enter the CIDR for subnet1 of vpc1" }
尽管它排在第五位
地形学不做排序。我认为,在VPC cidr之前就提出关于子网cidr的问题是不合适的
不幸的是,没有。它是按字母顺序排列的 尝试以下操作:将以下代码放入
.tf
文件中,然后运行地形平面图
:
variable "z" { description = "var z" }
variable "b" { description = "var b" }
variable "a" { description = "var a" }
如果需要按特定顺序提示用户,可以编写一个包装器脚本,将值馈送到
.tfvars
文件中。Terraform不是程序性的,它是声明性的,因此所有内容都被视为“一次”。这种表达方式是,在OP的例子中,这些问题将以随机顺序提问,而不是每次都以相同的顺序提问